@ccrf01/react-native-template 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/.github/workflows/npm-publish.yml +28 -0
  2. package/.vscode/settings.json +15 -0
  3. package/README.md +58 -0
  4. package/package.json +16 -0
  5. package/template/.bundle/config +2 -0
  6. package/template/.env.development +1 -0
  7. package/template/.env.production +1 -0
  8. package/template/.eslintrc.js +392 -0
  9. package/template/.java-version +1 -0
  10. package/template/.prettierrc.js +5 -0
  11. package/template/.ruby-version +1 -0
  12. package/template/.watchmanconfig +1 -0
  13. package/template/Gemfile +23 -0
  14. package/template/Gemfile.lock +330 -0
  15. package/template/README.md +97 -0
  16. package/template/ReactotronConfig.js +17 -0
  17. package/template/__tests__/App.test.tsx +13 -0
  18. package/template/_gitignore +75 -0
  19. package/template/_node-version +1 -0
  20. package/template/android/app/build.gradle +162 -0
  21. package/template/android/app/debug.keystore +0 -0
  22. package/template/android/app/proguard-rules.pro +10 -0
  23. package/template/android/app/src/debug/AndroidManifest.xml +9 -0
  24. package/template/android/app/src/main/AndroidManifest.xml +26 -0
  25. package/template/android/app/src/main/java/com/projectname/MainActivity.kt +30 -0
  26. package/template/android/app/src/main/java/com/projectname/MainApplication.kt +27 -0
  27. package/template/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
  28. package/template/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  29. package/template/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  30. package/template/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  31. package/template/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  32. package/template/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  33. package/template/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  34. package/template/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  35. package/template/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  36. package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  37. package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  38. package/template/android/app/src/main/res/values/strings.xml +3 -0
  39. package/template/android/app/src/main/res/values/styles.xml +9 -0
  40. package/template/android/build.gradle +37 -0
  41. package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  42. package/template/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  43. package/template/android/gradle.properties +48 -0
  44. package/template/android/gradlew +251 -0
  45. package/template/android/gradlew.bat +99 -0
  46. package/template/android/keystore/keystore.properties +4 -0
  47. package/template/android/settings.gradle +6 -0
  48. package/template/android/version.properties +2 -0
  49. package/template/app.json +4 -0
  50. package/template/babel.config.js +38 -0
  51. package/template/fastlane/Fastfile +136 -0
  52. package/template/fastlane/Pluginfile +9 -0
  53. package/template/fastlane/README.md +46 -0
  54. package/template/index.js +9 -0
  55. package/template/ios/.xcode.env +11 -0
  56. package/template/ios/Podfile +35 -0
  57. package/template/ios/Podfile.lock +3669 -0
  58. package/template/ios/ProjectName/AppDelegate.swift +48 -0
  59. package/template/ios/ProjectName/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  60. package/template/ios/ProjectName/Images.xcassets/Contents.json +6 -0
  61. package/template/ios/ProjectName/Info.plist +66 -0
  62. package/template/ios/ProjectName/LaunchScreen.storyboard +47 -0
  63. package/template/ios/ProjectName/PrivacyInfo.xcprivacy +47 -0
  64. package/template/ios/ProjectName.xcodeproj/project.pbxproj +482 -0
  65. package/template/ios/ProjectName.xcodeproj/xcshareddata/xcschemes/ProjectName.xcscheme +88 -0
  66. package/template/ios/ProjectName.xcworkspace/contents.xcworkspacedata +10 -0
  67. package/template/jest.config.js +3 -0
  68. package/template/metro.config.js +20 -0
  69. package/template/package-lock.json +17073 -0
  70. package/template/package.json +156 -0
  71. package/template/src/@types/emotion.d.ts +12 -0
  72. package/template/src/@types/env.d.ts +3 -0
  73. package/template/src/@types/redux-persist-transform-immutable.d.ts +1 -0
  74. package/template/src/@types/typing.d.ts +17 -0
  75. package/template/src/AppContainer.tsx +109 -0
  76. package/template/src/assets/images/143.png +0 -0
  77. package/template/src/assets/index.ts +13 -0
  78. package/template/src/components/basic/BackButton/index.tsx +34 -0
  79. package/template/src/components/basic/Body/index.tsx +68 -0
  80. package/template/src/components/basic/Button/index.tsx +181 -0
  81. package/template/src/components/basic/Button/utils.ts +78 -0
  82. package/template/src/components/basic/ButtonGroup/index.tsx +182 -0
  83. package/template/src/components/basic/Card/index.tsx +3 -0
  84. package/template/src/components/basic/Container/index.tsx +38 -0
  85. package/template/src/components/basic/Content/index.tsx +87 -0
  86. package/template/src/components/basic/DropDown/index.tsx +354 -0
  87. package/template/src/components/basic/ExpandableOverlay/index.tsx +113 -0
  88. package/template/src/components/basic/Header/index.tsx +216 -0
  89. package/template/src/components/basic/Header/styles.ts +0 -0
  90. package/template/src/components/basic/Icons/index.tsx +131 -0
  91. package/template/src/components/basic/InputLabel/index.tsx +19 -0
  92. package/template/src/components/basic/LoadingOverlay/index.tsx +68 -0
  93. package/template/src/components/basic/MaterialTextInput/index.tsx +153 -0
  94. package/template/src/components/basic/NumberInput/index.tsx +53 -0
  95. package/template/src/components/basic/Picker/PickerContext.ts +7 -0
  96. package/template/src/components/basic/Picker/PickerHeader.tsx +130 -0
  97. package/template/src/components/basic/Picker/PickerItem.tsx +105 -0
  98. package/template/src/components/basic/Picker/PickerItemsList.tsx +135 -0
  99. package/template/src/components/basic/Picker/PickerPresenter.ts +54 -0
  100. package/template/src/components/basic/Picker/hooks/useImperativePickerHandle.ts +27 -0
  101. package/template/src/components/basic/Picker/hooks/usePickerLabel.ts +74 -0
  102. package/template/src/components/basic/Picker/hooks/usePickerSearch.ts +37 -0
  103. package/template/src/components/basic/Picker/hooks/usePickerSelection.ts +57 -0
  104. package/template/src/components/basic/Picker/index.tsx +284 -0
  105. package/template/src/components/basic/Picker/types.tsx +229 -0
  106. package/template/src/components/basic/PressableOpacity/index.tsx +20 -0
  107. package/template/src/components/basic/RootDialog/Dialog.tsx +246 -0
  108. package/template/src/components/basic/RootDialog/Manager.tsx +110 -0
  109. package/template/src/components/basic/RootDialog/animations/Animation.ts +29 -0
  110. package/template/src/components/basic/RootDialog/animations/FadeAnimation.ts +40 -0
  111. package/template/src/components/basic/RootDialog/animations/ScaleAnimation.ts +37 -0
  112. package/template/src/components/basic/RootDialog/animations/SlideAnimation.ts +89 -0
  113. package/template/src/components/basic/RootDialog/components/Backdrop.tsx +60 -0
  114. package/template/src/components/basic/RootDialog/components/BaseDialog.tsx +564 -0
  115. package/template/src/components/basic/RootDialog/components/BottomDialog.tsx +32 -0
  116. package/template/src/components/basic/RootDialog/components/DialogButton.tsx +87 -0
  117. package/template/src/components/basic/RootDialog/components/DialogContent.tsx +26 -0
  118. package/template/src/components/basic/RootDialog/components/DialogContext.tsx +8 -0
  119. package/template/src/components/basic/RootDialog/components/DialogFooter.tsx +42 -0
  120. package/template/src/components/basic/RootDialog/components/DialogTitle.tsx +53 -0
  121. package/template/src/components/basic/RootDialog/components/DraggableView.tsx +271 -0
  122. package/template/src/components/basic/RootDialog/index.ts +21 -0
  123. package/template/src/components/basic/RootDialog/type.ts +102 -0
  124. package/template/src/components/basic/Text/index.tsx +8 -0
  125. package/template/src/components/basic/index.ts +35 -0
  126. package/template/src/configs/constants/type/APIStatus.type.ts +8 -0
  127. package/template/src/configs/constants/type/Locale.type.ts +7 -0
  128. package/template/src/configs/constants/type/StorageKey.type.ts +7 -0
  129. package/template/src/configs/constants/type/ThemeType.type.ts +6 -0
  130. package/template/src/configs/constants/type/index.ts +11 -0
  131. package/template/src/configs/index.ts +22 -0
  132. package/template/src/contexts/ThemeContext.ts +6 -0
  133. package/template/src/hooks/useAppLoading.ts +26 -0
  134. package/template/src/hooks/useAppState.ts +36 -0
  135. package/template/src/hooks/useArray.ts +47 -0
  136. package/template/src/hooks/useAsync.ts +42 -0
  137. package/template/src/hooks/useAsyncStorage.ts +41 -0
  138. package/template/src/hooks/useBoolean.ts +21 -0
  139. package/template/src/hooks/useBuildTheme.ts +249 -0
  140. package/template/src/hooks/useCountDown.ts +111 -0
  141. package/template/src/hooks/useCounter.ts +27 -0
  142. package/template/src/hooks/useDebounce.ts +25 -0
  143. package/template/src/hooks/useDebouncedValidate.ts +32 -0
  144. package/template/src/hooks/useDebugInformation.ts +38 -0
  145. package/template/src/hooks/useDeviceToken.ts +20 -0
  146. package/template/src/hooks/useEncryptedStorage.ts +41 -0
  147. package/template/src/hooks/useFontFamily.ts +13 -0
  148. package/template/src/hooks/useHttp.ts +18 -0
  149. package/template/src/hooks/useInterval.ts +24 -0
  150. package/template/src/hooks/useIsForeground.ts +17 -0
  151. package/template/src/hooks/useMMKVStorage.ts +0 -0
  152. package/template/src/hooks/usePrevious.ts +12 -0
  153. package/template/src/hooks/useRenderCount.ts +10 -0
  154. package/template/src/hooks/useTheme.ts +17 -0
  155. package/template/src/hooks/useTimeCountDown.ts +91 -0
  156. package/template/src/index.tsx +65 -0
  157. package/template/src/infrastructures/NetClient/AbstractClient.ts +66 -0
  158. package/template/src/infrastructures/NetClient/ApiResponse.ts +16 -0
  159. package/template/src/infrastructures/NetClient/ApisauceClient.ts +76 -0
  160. package/template/src/infrastructures/NetClient/AxiosClient.ts +80 -0
  161. package/template/src/infrastructures/NetClient/FetchNetClient.ts +120 -0
  162. package/template/src/infrastructures/NetClient/config.ts +3 -0
  163. package/template/src/infrastructures/NetClient/interfaces/INetClient.ts +6 -0
  164. package/template/src/infrastructures/Storage/IStorage.ts +7 -0
  165. package/template/src/infrastructures/Storage/MMKVStorage.ts +41 -0
  166. package/template/src/infrastructures/common/Timeout.ts +27 -0
  167. package/template/src/infrastructures/common/colorUtils.ts +82 -0
  168. package/template/src/infrastructures/common/dateUtils.ts +39 -0
  169. package/template/src/infrastructures/common/logger.ts +115 -0
  170. package/template/src/locales/en-US/general.json +26 -0
  171. package/template/src/locales/en-US/index.ts +9 -0
  172. package/template/src/locales/en-US/screens.json +4 -0
  173. package/template/src/locales/en-US/setting.json +3 -0
  174. package/template/src/locales/i18n.ts +109 -0
  175. package/template/src/locales/zh-TW/general.json +26 -0
  176. package/template/src/locales/zh-TW/index.ts +9 -0
  177. package/template/src/locales/zh-TW/screens.json +4 -0
  178. package/template/src/locales/zh-TW/setting.json +3 -0
  179. package/template/src/models/index.ts +5 -0
  180. package/template/src/models/request.model.ts +50 -0
  181. package/template/src/navigators/DrawerNav/DrawerContent.tsx +66 -0
  182. package/template/src/navigators/DrawerNav/DrawerItem.tsx +261 -0
  183. package/template/src/navigators/DrawerNav/index.tsx +39 -0
  184. package/template/src/navigators/DrawerNav/props.ts +12 -0
  185. package/template/src/navigators/DrawerNav/types.ts +8 -0
  186. package/template/src/navigators/MainBottomTabNav/index.tsx +83 -0
  187. package/template/src/navigators/MainBottomTabNav/props.ts +16 -0
  188. package/template/src/navigators/MainBottomTabNav/types.ts +6 -0
  189. package/template/src/navigators/RootStack.tsx +43 -0
  190. package/template/src/navigators/index.tsx +40 -0
  191. package/template/src/navigators/props.ts +14 -0
  192. package/template/src/navigators/types.ts +18 -0
  193. package/template/src/navigators/utils.ts +68 -0
  194. package/template/src/redux/api/api.ts +41 -0
  195. package/template/src/redux/reducers/appSlice.ts +26 -0
  196. package/template/src/redux/reducers/index.ts +21 -0
  197. package/template/src/redux/reducers/nonPersistSlice.ts +51 -0
  198. package/template/src/redux/reducers/settingSlice.ts +48 -0
  199. package/template/src/redux/reducers/themeSlice.ts +55 -0
  200. package/template/src/redux/saga/index.ts +5 -0
  201. package/template/src/redux/saga/settingSaga.ts +21 -0
  202. package/template/src/redux/selectors/app.ts +9 -0
  203. package/template/src/redux/selectors/nonPersist.ts +23 -0
  204. package/template/src/redux/selectors/setting.ts +29 -0
  205. package/template/src/redux/selectors/theme.ts +13 -0
  206. package/template/src/redux/store/index.ts +79 -0
  207. package/template/src/redux/store/types.d.ts +5 -0
  208. package/template/src/screens/Home/index.tsx +146 -0
  209. package/template/src/screens/Settings/components/Item.tsx +45 -0
  210. package/template/src/screens/Settings/index.tsx +97 -0
  211. package/template/src/screens/Splash/index.tsx +53 -0
  212. package/template/src/services/Dialogs.tsx +226 -0
  213. package/template/src/services/PermissionCheck.ts +257 -0
  214. package/template/src/theme/Common.ts +48 -0
  215. package/template/src/theme/Fonts.ts +196 -0
  216. package/template/src/theme/Gutters.ts +63 -0
  217. package/template/src/theme/Icons.ts +28 -0
  218. package/template/src/theme/Images.ts +13 -0
  219. package/template/src/theme/Layout.ts +106 -0
  220. package/template/src/theme/Variables.ts +167 -0
  221. package/template/src/theme/components/Buttons.ts +37 -0
  222. package/template/src/theme/index.ts +8 -0
  223. package/template/src/theme/metrics.ts +57 -0
  224. package/template/src/theme/themes/default_dark/Images.ts +7 -0
  225. package/template/src/theme/themes/default_dark/Variables.ts +84 -0
  226. package/template/src/theme/themes/default_dark/index.ts +2 -0
  227. package/template/src/theme/themes/index.ts +8 -0
  228. package/template/src/theme/types.ts +152 -0
  229. package/template/src/utils/encrypt-helper.ts +118 -0
  230. package/template/src/utils/index.ts +76 -0
  231. package/template/src/utils/sys-info-data.ts +17 -0
  232. package/template/tsconfig.json +44 -0
  233. package/template.config.js +8 -0
@@ -0,0 +1,564 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import React, { Component, Fragment, useCallback, useEffect, useImperativeHandle } from 'react'
3
+ import {
4
+ Animated,
5
+ BackHandler as RNBackHandler,
6
+ Dimensions,
7
+ StyleSheet,
8
+ Text,
9
+ TouchableOpacity,
10
+ View,
11
+ } from 'react-native'
12
+ import useState from 'react-usestateref'
13
+
14
+ import logger from '@/infrastructures/common/logger'
15
+
16
+ import Animation from '../animations/Animation'
17
+ import FadeAnimation from '../animations/FadeAnimation'
18
+ import type { DialogProps, DragEvent } from '../type'
19
+ import Backdrop from './Backdrop'
20
+ import DialogContext from './DialogContext'
21
+ import DraggableView from './DraggableView'
22
+
23
+ const BackHandler = RNBackHandler
24
+
25
+ // dialog states
26
+ const MODAL_OPENING: string = 'opening'
27
+ const MODAL_OPENED: string = 'opened'
28
+ const MODAL_CLOSING: string = 'closing'
29
+ const MODAL_CLOSED: string = 'closed'
30
+
31
+ // default dialog config
32
+ const DEFAULT_ANIMATION_DURATION: number = 150
33
+
34
+ // event types
35
+ const HARDWARE_BACK_PRESS_EVENT = 'hardwareBackPress'
36
+
37
+ const styles = StyleSheet.create({
38
+ container: {
39
+ ...StyleSheet.absoluteFillObject,
40
+ zIndex: 1000,
41
+ elevation: 10,
42
+ },
43
+ modal: {
44
+ overflow: 'hidden',
45
+ backgroundColor: '#ffffff',
46
+ },
47
+ hidden: {
48
+ top: -10000,
49
+ left: 0,
50
+ height: 0,
51
+ width: 0,
52
+ },
53
+ round: { borderRadius: 8 },
54
+ draggableView: {
55
+ flex: 1,
56
+ justifyContent: 'center',
57
+ alignItems: 'center',
58
+ },
59
+ })
60
+
61
+ type DialogState =
62
+ | typeof MODAL_OPENING
63
+
64
+
65
+ type State = {
66
+ modalAnimation: Animation
67
+ modalState: DialogState
68
+ }
69
+
70
+ class BaseDialogBK extends Component<DialogProps, State> {
71
+ static defaultProps = {
72
+ rounded: true,
73
+ modalTitle: null,
74
+ visible: false,
75
+ style: null,
76
+ animationDuration: DEFAULT_ANIMATION_DURATION,
77
+ modalStyle: null,
78
+ width: null,
79
+ height: null,
80
+ onTouchOutside: () => { },
81
+ onHardwareBackPress: () => false,
82
+ hasOverlay: true,
83
+ overlayOpacity: 0.5,
84
+ overlayPointerEvents: null,
85
+ overlayBackgroundColor: '#000',
86
+ onShow: () => { },
87
+ onDismiss: () => { },
88
+ footer: null,
89
+ onMove: () => { },
90
+ onSwiping: () => { },
91
+ onSwipeRelease: () => { },
92
+ onSwipingOut: () => { },
93
+ useNativeDriver: true,
94
+ }
95
+
96
+ isSwipingOut: boolean
97
+ lastSwipeEvent: DragEvent | undefined
98
+ backdrop: React.RefObject<Backdrop | null>
99
+ constructor(props: DialogProps) {
100
+ super(props)
101
+
102
+ this.isSwipingOut = false
103
+ this.lastSwipeEvent = undefined
104
+ this.backdrop = React.createRef<Backdrop | null>()
105
+ this.state = {
106
+ modalAnimation: props.modalAnimation || new FadeAnimation({ animationDuration: props.animationDuration }),
107
+ modalState: MODAL_CLOSED,
108
+ }
109
+ }
110
+
111
+ componentDidMount() {
112
+ if (this.props.visible) {
113
+ this.show()
114
+ }
115
+ BackHandler.addEventListener(HARDWARE_BACK_PRESS_EVENT, this.onHardwareBackPress)
116
+ }
117
+
118
+ componentDidUpdate(prevProps: DialogProps) {
119
+ if (this.props.visible !== prevProps.visible) {
120
+ if (this.props.visible) {
121
+ this.show()
122
+
123
+ return
124
+ }
125
+ this.dismiss()
126
+ }
127
+ }
128
+
129
+ componentWillUnmount() {
130
+ BackHandler.removeEventListener(HARDWARE_BACK_PRESS_EVENT, this.onHardwareBackPress)
131
+ }
132
+
133
+ onHardwareBackPress = (): boolean => {
134
+ const { onHardwareBackPress } = this.props
135
+ if (onHardwareBackPress !== undefined) {
136
+ return onHardwareBackPress()
137
+ }
138
+
139
+ return false
140
+ }
141
+
142
+ get pointerEvents(): 'auto' | 'none' {
143
+ const { overlayPointerEvents } = this.props
144
+ const { modalState } = this.state
145
+ if (overlayPointerEvents) {
146
+ return overlayPointerEvents
147
+ }
148
+
149
+ return modalState === MODAL_OPENED ? 'auto' : 'none'
150
+ }
151
+
152
+ get modalSize(): { width: number; height: number } {
153
+ const { height: screenHeight, width: screenWidth } = Dimensions.get('window')
154
+ let { height = 0, width = 0 } = this.props
155
+ if (width && width > 0.0 && width <= 1.0) {
156
+ width *= screenWidth
157
+ }
158
+ if (height && height > 0.0 && height <= 1.0) {
159
+ height *= screenHeight
160
+ }
161
+
162
+ return {
163
+ width,
164
+ height,
165
+ }
166
+ }
167
+
168
+ show(): void {
169
+ this.setState({ modalState: MODAL_OPENING }, () => {
170
+ this.state.modalAnimation.in(() => {
171
+ this.setState({ modalState: MODAL_OPENED }, this.props.onShow)
172
+ })
173
+ })
174
+ }
175
+
176
+ dismiss(): void {
177
+ this.setState({ modalState: MODAL_CLOSING }, () => {
178
+ if (this.isSwipingOut) {
179
+ this.setState({ modalState: MODAL_CLOSED }, this.props.onDismiss)
180
+
181
+ return
182
+ }
183
+ this.state.modalAnimation.out(() => {
184
+ this.setState({ modalState: MODAL_CLOSED }, this.props.onDismiss)
185
+ })
186
+ })
187
+ }
188
+
189
+ handleMove = (event: DragEvent): void => {
190
+ // prevent flashing when modal is closing and onMove callback invoked
191
+ if (this.state.modalState === MODAL_CLOSING) {
192
+ return
193
+ }
194
+ if (!this.lastSwipeEvent) {
195
+ this.lastSwipeEvent = event
196
+ }
197
+ let newOpacity
198
+ const { overlayOpacity: opacity = 1.0 } = this.props
199
+ // const opacity = this.props.overlayOpacity;
200
+ if (Math.abs(event.axis.y)) {
201
+ const lastAxis = Math.abs(this.lastSwipeEvent.layout.y)
202
+ const currAxis = Math.abs(event.axis.y)
203
+ newOpacity = opacity - ((opacity * currAxis) / (Dimensions.get('window').height - lastAxis))
204
+ } else {
205
+ const lastAxis = Math.abs(this.lastSwipeEvent.layout.x)
206
+ const currAxis = Math.abs(event.axis.x)
207
+ newOpacity = opacity - ((opacity * currAxis) / (Dimensions.get('window').width - lastAxis))
208
+ }
209
+ this.backdrop?.current?.setOpacity(newOpacity)
210
+ }
211
+
212
+ handleSwipingOut = (event: DragEvent) => {
213
+ this.isSwipingOut = true
214
+ const { onSwipingOut } = this.props
215
+ if (onSwipingOut) {
216
+ onSwipingOut(event)
217
+ }
218
+ }
219
+
220
+ render() {
221
+ const { modalAnimation, modalState } = this.state
222
+ const {
223
+ animationDuration,
224
+ children,
225
+ footer,
226
+ hasOverlay,
227
+ modalStyle,
228
+ modalTitle,
229
+ onSwipeOut,
230
+ onSwipeRelease,
231
+ onSwiping,
232
+ onTouchOutside,
233
+ overlayBackgroundColor,
234
+ overlayOpacity,
235
+ rounded,
236
+ style,
237
+ swipeDirection,
238
+ swipeThreshold,
239
+ useNativeDriver,
240
+ } = this.props
241
+
242
+ const overlayVisible = hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState)
243
+ const round = rounded ? styles.round : null
244
+ const hidden = modalState === MODAL_CLOSED && styles.hidden
245
+
246
+ return (
247
+ <DialogContext.Provider
248
+ value={{
249
+ hasTitle: !!modalTitle,
250
+ hasFooter: !!footer,
251
+ }}
252
+ >
253
+ <View style={[styles.container, hidden]}>
254
+ <DraggableView
255
+ style={StyleSheet.flatten([styles.draggableView, style])}
256
+ onMove={this.handleMove}
257
+ onSwiping={onSwiping}
258
+ onRelease={onSwipeRelease}
259
+ onSwipingOut={this.handleSwipingOut}
260
+ onSwipeOut={onSwipeOut}
261
+ swipeDirection={swipeDirection}
262
+ swipeThreshold={swipeThreshold}
263
+ >
264
+ {({ onLayout, pan }) => (
265
+ <Fragment>
266
+ <Backdrop
267
+ ref={this.backdrop}
268
+ pointerEvents={this.pointerEvents}
269
+ visible={overlayVisible}
270
+ onPress={onTouchOutside}
271
+ backgroundColor={overlayBackgroundColor}
272
+ opacity={overlayOpacity}
273
+ animationDuration={animationDuration}
274
+ useNativeDriver={useNativeDriver}
275
+ />
276
+ <Animated.View
277
+ style={pan.getLayout()}
278
+ onLayout={onLayout}
279
+ >
280
+ <Animated.View
281
+ style={[
282
+ styles.modal,
283
+ round,
284
+ this.modalSize,
285
+ modalStyle,
286
+ modalAnimation.getAnimations(),
287
+ ]}
288
+ >
289
+ {modalTitle}
290
+ {children}
291
+ {footer}
292
+ </Animated.View>
293
+ </Animated.View>
294
+ </Fragment>
295
+ )}
296
+ </DraggableView>
297
+ </View>
298
+ </DialogContext.Provider>
299
+ )
300
+ }
301
+ }
302
+
303
+ export type Handle = {
304
+ dismiss: (onDismiss?: () => void) => void
305
+ }
306
+ const BaseDialogBase = (
307
+ {
308
+ animationDuration = DEFAULT_ANIMATION_DURATION,
309
+ children,
310
+ footer,
311
+ hasOverlay = true,
312
+ height,
313
+ modalAnimation: _modalAnimation,
314
+ modalStyle = null,
315
+ modalTitle,
316
+ onDismiss = () => { },
317
+ onHardwareBackPress = () => true,
318
+ onMove = () => { },
319
+ onShow = () => { },
320
+ onSwipeOut,
321
+ onSwipeRelease = () => { },
322
+ onSwiping = () => { },
323
+ onSwipingOut = () => { },
324
+ onTouchOutside = () => { },
325
+ overlayBackgroundColor = '#000',
326
+ overlayOpacity = 0.5,
327
+ overlayPointerEvents,
328
+ rounded = true,
329
+ style = null,
330
+ swipeDirection,
331
+ swipeThreshold,
332
+ useNativeDriver = true,
333
+ visible = false,
334
+ width,
335
+ }: DialogProps, ref: React.Ref<Handle>) => {
336
+ const [modalState, setModalState] = useState(MODAL_CLOSED)
337
+ const backdropRef = React.useRef<Backdrop>(null)
338
+ const isSwipingOut = React.useRef(false)
339
+ const lastSwipeEvent = React.useRef<DragEvent | null>(null)
340
+ const [modalAnimation, setModalAnimation] = useState(_modalAnimation || new FadeAnimation({ animationDuration }))
341
+
342
+ const dismissCB = React.useRef<(() => void) | undefined>(() => { })
343
+
344
+ useImperativeHandle(ref, () => ({
345
+ dismiss: (cb?: () => void) => {
346
+ dismissCB.current = cb
347
+ dismiss()
348
+ },
349
+ }))
350
+
351
+ useEffect(() => {
352
+ const event = BackHandler.addEventListener(HARDWARE_BACK_PRESS_EVENT, _onHardwareBackPress)
353
+
354
+ return () => {
355
+ event.remove()
356
+ }
357
+ }, [])
358
+
359
+ useEffect(() => {
360
+ if (visible) {
361
+ show()
362
+ } else {
363
+ dismiss()
364
+ }
365
+ }, [visible])
366
+
367
+ useEffect(() => {
368
+ if (modalState === MODAL_OPENED) {
369
+ onShow()
370
+ }
371
+ if (modalState === MODAL_CLOSING) {
372
+ if (isSwipingOut.current) {
373
+ setModalState(MODAL_CLOSED)
374
+ } else {
375
+ modalAnimation.out(() => {
376
+ setModalState(MODAL_CLOSED)
377
+ })
378
+ }
379
+ }
380
+ if (modalState === MODAL_CLOSED) {
381
+ onDismiss()
382
+ if (dismissCB.current) {
383
+ dismissCB.current()
384
+ }
385
+ }
386
+ }, [modalState])
387
+
388
+
389
+ const pointerEvents = React.useMemo(() => {
390
+ if (overlayPointerEvents) {
391
+ return overlayPointerEvents
392
+ }
393
+
394
+ return modalState === MODAL_OPENED ? 'auto' : 'none'
395
+ }, [overlayPointerEvents, modalState])
396
+
397
+ const modalSize = React.useMemo(() => {
398
+ const { height: screenHeight, width: screenWidth } = Dimensions.get('window')
399
+ if (width && width > 0.0 && width <= 1.0) {
400
+ width *= screenWidth
401
+ }
402
+ if (height && height > 0.0 && height <= 1.0) {
403
+ height *= screenHeight
404
+ }
405
+
406
+ return {
407
+ width,
408
+ height,
409
+ }
410
+ }, [height, width])
411
+
412
+ // logger.log('modalSize', modalSize)
413
+
414
+ const hidden = React.useMemo(() => {
415
+ if (modalState === MODAL_CLOSED) {
416
+ return styles.hidden
417
+ }
418
+
419
+ return null
420
+ }, [modalState])
421
+ const overlayVisible = React.useMemo(() => {
422
+ return hasOverlay && [MODAL_OPENING, MODAL_OPENED].includes(modalState)
423
+ }, [modalState, hasOverlay])
424
+ const round = React.useMemo(() => { return rounded ? styles.round : null }, [rounded])
425
+
426
+ const handleMove = useCallback((event: DragEvent): void => {
427
+ // prevent flashing when modal is closing and onMove callback invoked
428
+ if (modalState === MODAL_CLOSING) {
429
+ return
430
+ }
431
+ if (!lastSwipeEvent?.current) {
432
+ lastSwipeEvent.current = event
433
+ }
434
+ let newOpacity
435
+ const opacity = overlayOpacity || 1
436
+ // const opacity = this.props.overlayOpacity;
437
+ if (Math.abs(event.axis.y)) {
438
+ const lastAxis = Math.abs(lastSwipeEvent.current.layout.y)
439
+ const currAxis = Math.abs(event.axis.y)
440
+ newOpacity = opacity - ((opacity * currAxis) / (Dimensions.get('window').height - lastAxis))
441
+ } else {
442
+ const lastAxis = Math.abs(lastSwipeEvent.current.layout.x)
443
+ const currAxis = Math.abs(event.axis.x)
444
+ newOpacity = opacity - ((opacity * currAxis) / (Dimensions.get('window').width - lastAxis))
445
+ }
446
+ backdropRef?.current?.setOpacity(newOpacity)
447
+ }, [modalState, overlayOpacity])
448
+
449
+ const handleSwipingOut = (event: DragEvent) => {
450
+ isSwipingOut.current = true
451
+ onSwipingOut?.(event)
452
+ }
453
+
454
+ const _onHardwareBackPress = (): boolean => {
455
+ if (onHardwareBackPress !== undefined) {
456
+ return onHardwareBackPress()
457
+ }
458
+
459
+ return false
460
+ }
461
+
462
+ const show = () => {
463
+ logger.log('call show')
464
+ setModalState(MODAL_OPENING)
465
+ modalAnimation.in(() => {
466
+ setModalState(MODAL_OPENED)
467
+ })
468
+ }
469
+
470
+ const dismiss = () => {
471
+ logger.log('call dismiss')
472
+ setModalState(MODAL_CLOSING)
473
+ }
474
+
475
+ return (
476
+ <View style={[styles.container, hidden]}>
477
+ {/* <DraggableView
478
+ style={StyleSheet.flatten([styles.draggableView, style])}
479
+ onMove={handleMove}
480
+ onSwiping={onSwiping}
481
+ onRelease={onSwipeRelease}
482
+ onSwipingOut={handleSwipingOut}
483
+ onSwipeOut={onSwipeOut}
484
+ swipeDirection={swipeDirection}
485
+ swipeThreshold={swipeThreshold}
486
+ >
487
+ {({ onLayout, pan }) => (
488
+ <Fragment>
489
+ <Backdrop
490
+ ref={backdropRef}
491
+ pointerEvents={pointerEvents}
492
+ visible={overlayVisible}
493
+ onPress={onTouchOutside}
494
+ backgroundColor={overlayBackgroundColor}
495
+ opacity={overlayOpacity}
496
+ animationDuration={animationDuration}
497
+ useNativeDriver={useNativeDriver}
498
+ />
499
+ <Animated.View
500
+ style={pan.getLayout()}
501
+ onLayout={onLayout}
502
+ >
503
+ <Animated.View
504
+ style={[
505
+ styles.modal,
506
+ round,
507
+ modalSize,
508
+ modalStyle,
509
+ modalAnimation.getAnimations(),
510
+ ]}
511
+ >
512
+ {modalTitle}
513
+ {children}
514
+ {footer}
515
+ <TouchableOpacity
516
+ style={{ padding: 20 }}
517
+ onPress={() => {
518
+ logger.log('close')
519
+ }}
520
+ >
521
+ <Text>Close</Text>
522
+ </TouchableOpacity>
523
+ </Animated.View>
524
+ </Animated.View>
525
+ </Fragment>
526
+ )}
527
+ </DraggableView> */}
528
+ <View
529
+ style={StyleSheet.flatten([styles.draggableView, style])}
530
+ >
531
+ <Fragment>
532
+ <Backdrop
533
+ ref={backdropRef}
534
+ pointerEvents={pointerEvents}
535
+ visible={overlayVisible}
536
+ onPress={onTouchOutside}
537
+ backgroundColor={overlayBackgroundColor}
538
+ opacity={overlayOpacity}
539
+ animationDuration={animationDuration}
540
+ useNativeDriver={useNativeDriver}
541
+ />
542
+ <Animated.View >
543
+ <Animated.View
544
+ style={[
545
+ styles.modal,
546
+ round,
547
+ modalSize,
548
+ modalStyle,
549
+ modalAnimation.getAnimations(),
550
+ ]}
551
+ >
552
+ {modalTitle}
553
+ {children}
554
+ {footer}
555
+ </Animated.View>
556
+ </Animated.View>
557
+ </Fragment>
558
+ </View>
559
+ </View>
560
+ )
561
+ }
562
+
563
+ export type BaseDialog = Handle
564
+ export const BaseDialog = React.forwardRef(BaseDialogBase)
@@ -0,0 +1,32 @@
1
+ import React from 'react'
2
+ import { StyleSheet } from 'react-native'
3
+
4
+ import SlideAnimation from '../animations/SlideAnimation'
5
+ import Dialog from '../Dialog'
6
+ import type { DialogProps } from '../type'
7
+
8
+ const styles = StyleSheet.create({
9
+ container: { justifyContent: 'flex-end' },
10
+ modal: {
11
+ borderBottomRightRadius: 0,
12
+ borderBottomLeftRadius: 0,
13
+ },
14
+ })
15
+
16
+ const BottomDialog = ({
17
+ modalStyle,
18
+ style,
19
+ ...restProps
20
+ }: DialogProps) =>
21
+ (
22
+ <Dialog
23
+ modalAnimation={new SlideAnimation({ slideFrom: 'bottom' })}
24
+ {...restProps}
25
+ style={StyleSheet.flatten([styles.container, style])}
26
+ modalStyle={StyleSheet.flatten([styles.modal, modalStyle])}
27
+ width={1}
28
+ swipeDirection="down"
29
+ />
30
+ )
31
+
32
+ export default BottomDialog
@@ -0,0 +1,87 @@
1
+ import React from 'react'
2
+ import { StyleSheet } from 'react-native'
3
+ import { Button as PButton, withTheme } from 'react-native-paper'
4
+
5
+ import { Button } from '@/components/basic'
6
+ import useTheme from '@/hooks/useTheme'
7
+
8
+ import type { DialogButtonProps } from '../type'
9
+
10
+ const styles = StyleSheet.create({
11
+ text: {
12
+ // fontWeight: isAndroid ? '400' : '500',
13
+ // fontFamily: isAndroid ? 'sans-serif-medium' : 'System',
14
+ // fontSize: isAndroid ? 19 : 15,
15
+ // color: '#044DE0',
16
+ // color: '#000',
17
+ // ...buttonFontStyle,
18
+ },
19
+ disable: { color: '#C5C6C5' },
20
+ })
21
+
22
+ const DialogButton = (props: DialogButtonProps) => {
23
+ const { Colors, Common, Fonts } = useTheme()
24
+
25
+ const {
26
+ isCancel,
27
+ onPress,
28
+ style = {},
29
+ text,
30
+ textStyle = {},
31
+ type,
32
+ ...restProps
33
+ } = props
34
+ // const {
35
+ // align = 'center',
36
+ // label,
37
+ // labelStyle = {},
38
+ // style = {},
39
+ // mode = 'text',
40
+ // ...restProps
41
+ // } = props
42
+ // const buttonAlign = { alignSelf: align ? align : 'center' }
43
+
44
+ // return (
45
+ // <>
46
+ // <Button
47
+ // style={[
48
+ // style,
49
+ // buttonAlign,
50
+ // ]}
51
+ // labelStyle={StyleSheet.flatten([
52
+ // styles.text,
53
+ // // Fonts.buttonTextMedium,
54
+ // labelStyle,
55
+ // ])}
56
+ // {...restProps}
57
+ // >
58
+ // {label}
59
+ // </Button>
60
+ // </>
61
+ // // <Text>ABc</Text>
62
+ // )
63
+
64
+ let _buttonStyle = style
65
+ let _textStyle = textStyle
66
+ if (isCancel) {
67
+ _buttonStyle = Object.assign(_buttonStyle, {
68
+ backgroundColor: Colors.negative,
69
+ })
70
+ _textStyle = Object.assign(_textStyle, {
71
+ color: Colors.onNegative,
72
+ })
73
+ }
74
+
75
+ return (
76
+ <Button
77
+ type={type}
78
+ text={text}
79
+ textStyle={_textStyle}
80
+ style={_buttonStyle}
81
+ onPress={onPress}
82
+ {...restProps}
83
+ />
84
+ )
85
+ }
86
+
87
+ export default DialogButton
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import { StyleSheet, View } from 'react-native'
3
+
4
+ import type { DialogContentProps } from '../type'
5
+ import DialogContext from './DialogContext'
6
+
7
+ const styles = StyleSheet.create({
8
+ content: {
9
+ paddingVertical: 24,
10
+ paddingHorizontal: 18,
11
+ },
12
+ noPaddingTop: { paddingTop: 0 },
13
+ })
14
+
15
+ const DialogContent = ({ children, style }: DialogContentProps) =>
16
+ (
17
+ <DialogContext.Consumer>
18
+ {({ hasTitle }) => (
19
+ <View style={[styles.content, false && styles.noPaddingTop, style]}>
20
+ {children}
21
+ </View>
22
+ )}
23
+ </DialogContext.Consumer>
24
+ )
25
+
26
+ export default DialogContent
@@ -0,0 +1,8 @@
1
+ import React from 'react'
2
+
3
+ const DialogContext = React.createContext({
4
+ hasTitle: false,
5
+ hasFooter: false,
6
+ })
7
+
8
+ export default DialogContext