Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. import React from 'react';
  2. import { View } from 'react-native';
  3. import Tips from 'react-native-tips';
  4. import _ from 'lodash';
  5.  
  6. import AButton from '../../Components/AButton';
  7. import AText from '../../Components/AText';
  8. import CoachMarkConstant from '../../common/Constants/CoachMarkConstant';
  9. import { translate } from '../../Localization';
  10.  
  11. type Props = {
  12. children: any,
  13. isCoachMark: boolean,
  14. visible: boolean,
  15. coachMarkNextTips?: Function,
  16. position?: string,
  17. message: string,
  18. hasButton?: boolean,
  19. buttonText?: string,
  20. accessibilityLabel?: string,
  21. accessibilityLabelForButton?: string,
  22. customContainerStyle?: any,
  23. customContentStyle?: any,
  24. customChildrenStyle?: any,
  25. enableChildrenInteraction?: boolean;
  26. delay?: number;
  27. onRequestClose?: Function;
  28. };
  29.  
  30. const PREVENT_NEXT_COACH_MARK_TIMEOUT = 1000;
  31. const debounceOptions = {
  32. leading: true,
  33. trailing: false,
  34. };
  35.  
  36. const coachMarkRenderTips = (
  37. message,
  38. hasButton,
  39. buttonText,
  40. onPress,
  41. accessibilityLabelForButton,
  42. ) => {
  43. return (
  44. <View>
  45. <AText
  46. text={message}
  47. textStyle={CoachMarkConstant.tipsText}
  48. />
  49. {
  50. hasButton ?
  51. <AButton.BoxRounded
  52. accessibilityLabel={accessibilityLabelForButton}
  53. title={buttonText}
  54. onPressFn={_.debounce(onPress, PREVENT_NEXT_COACH_MARK_TIMEOUT, debounceOptions)}
  55. customButtonStyle={CoachMarkConstant.tipsButton.buttonStyle}
  56. />
  57. : null
  58. }
  59. </View>
  60. );
  61. };
  62.  
  63. export default function CoachMark(props: Props) {
  64. const {
  65. children, isCoachMark, visible, coachMarkNextTips, position, message, hasButton,
  66. buttonText, accessibilityLabel, accessibilityLabelForButton, customContentStyle,
  67. customContainerStyle, customChildrenStyle, enableChildrenInteraction, delay, onRequestClose,
  68. } = props;
  69.  
  70. return (
  71. isCoachMark ?
  72. <Tips
  73. accessibilityLabel={accessibilityLabel}
  74. visible={visible}
  75. content={
  76. coachMarkRenderTips(
  77. message, hasButton, buttonText, coachMarkNextTips,
  78. accessibilityLabelForButton,
  79. )
  80. }
  81. tooltipContainerStyle={[CoachMarkConstant.tipContainer.tooltipContainerStyle,
  82. customContainerStyle]}
  83. style={[CoachMarkConstant.tipContainer.style, customContentStyle]}
  84. modalStyle={CoachMarkConstant.tipContainer.modalStyle}
  85. childrenStyle={customChildrenStyle}
  86. contentStyle={[CoachMarkConstant.tipContainer.contentStyle, customContentStyle]}
  87. tooltipArrowStyle={CoachMarkConstant.tipContainer.tooltipArrowStyle}
  88. position={position}
  89. delay={delay}
  90. enableChildrenInteraction={enableChildrenInteraction}
  91. onRequestClose={onRequestClose}
  92. >
  93. {children}
  94. </Tips>
  95. :
  96. children
  97. );
  98. }
  99.  
  100. CoachMark.defaultProps = {
  101. coachMarkNextTips: null,
  102. position: 'bottom',
  103. hasButton: false,
  104. buttonText: translate('coachMark.default.buttonText'),
  105. accessibilityLabel: null,
  106. accessibilityLabelForButton: null,
  107. customContainerStyle: null,
  108. customContentStyle: null,
  109. customChildrenStyle: null,
  110. delay: 0,
  111. onRequestClose: null,
  112. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement