@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,246 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import React from 'react'
3
+ import { useTranslation } from 'react-i18next'
4
+ import { BackHandler, StyleProp, TextStyle, ViewStyle } from 'react-native'
5
+ import { Text } from 'react-native-paper'
6
+
7
+ import DialogManager, {
8
+ Dialog as RootDialog,
9
+ DialogButton,
10
+ DialogContent,
11
+ DialogFooter,
12
+ DialogTitle,
13
+ SlideAnimation,
14
+ } from '@/components/basic/RootDialog'
15
+ import logger from '@/infrastructures/common/logger'
16
+ import i18n from '@/locales/i18n'
17
+
18
+ interface IDialogAction {
19
+ label: string
20
+ onPress: () => void
21
+ buttonStyle?: ViewStyle
22
+ textStyle?: TextStyle
23
+ isCancel?: boolean
24
+ }
25
+ interface IDialogShowConfig {
26
+ title?: string
27
+ content: string | React.ReactElement
28
+ actions?: IDialogAction[]
29
+ clickBackdropDismiss?: boolean
30
+ }
31
+ interface IDialogConfirmConfig extends Omit<IDialogShowConfig, 'actions'> {
32
+ confirmText?: string
33
+ onConfirm?: () => void
34
+ onCancel?: () => void
35
+ }
36
+ interface IDialogInfoConfig extends Omit<IDialogShowConfig, 'actions'> {
37
+ confirmText?: string
38
+ onConfirm?: () => void
39
+ }
40
+
41
+ interface IDialogApiErrorConfig {
42
+ title?: string
43
+ message: string
44
+ onCancel?: () => void
45
+ allowRetry: boolean
46
+ onRetry?: () => unknown
47
+ }
48
+
49
+ export const confirm = ({
50
+ clickBackdropDismiss,
51
+ confirmText,
52
+ content,
53
+ onCancel,
54
+ onConfirm,
55
+ title,
56
+ }: IDialogConfirmConfig) => {
57
+ logger.log('confirm dialog called')
58
+ const { t } = i18n
59
+ const e = BackHandler.addEventListener('hardwareBackPress', () => {
60
+ return true
61
+ })
62
+ show({
63
+ title,
64
+ content,
65
+ clickBackdropDismiss,
66
+ actions: [
67
+ {
68
+ label: t('general:button.cancel'),
69
+ onPress: () => {
70
+ DialogManager.dismiss()
71
+ onCancel?.()
72
+ e?.remove()
73
+ },
74
+ isCancel: true,
75
+ },
76
+ {
77
+ label: confirmText || t('general:button.confirm'),
78
+ onPress: () => {
79
+ DialogManager.dismiss(() => {onConfirm?.()})
80
+ e?.remove()
81
+ },
82
+ },
83
+ ],
84
+ })
85
+ }
86
+
87
+ export const info = ({ clickBackdropDismiss, confirmText, content, onConfirm, title }: IDialogInfoConfig) => {
88
+ const { t } = i18n
89
+ const e = BackHandler.addEventListener('hardwareBackPress', () => {
90
+ return true
91
+ })
92
+ show({
93
+ title,
94
+ content,
95
+ clickBackdropDismiss,
96
+ actions: [
97
+ // {
98
+ // label: t('general:button.cancel'),
99
+ // onPress: () => {
100
+ // DialogManager.dismiss()
101
+ // onCancel?.()
102
+ // },
103
+ // isCancel: true,
104
+ // },
105
+ {
106
+ label: confirmText || t('general:button.confirm'),
107
+ onPress: () => {
108
+ logger.log('info dialog pressed confirm')
109
+ DialogManager.dismiss()
110
+ onConfirm?.()
111
+ e?.remove()
112
+ },
113
+ },
114
+ ],
115
+ })
116
+ }
117
+
118
+ export const apiError = ({ allowRetry, message, onCancel, onRetry, title }: IDialogApiErrorConfig) => {
119
+ const { t } = i18n
120
+ const e = BackHandler.addEventListener('hardwareBackPress', () => {
121
+ return true
122
+ })
123
+ const actions: IDialogAction[] = [
124
+ {
125
+ label: t('general:button.cancel'),
126
+ onPress: () => {
127
+ DialogManager.dismiss()
128
+ onCancel?.()
129
+ e?.remove()
130
+ },
131
+ isCancel: true,
132
+ },
133
+ ]
134
+ if (allowRetry) {
135
+ actions.push({
136
+ label: t('general:button.retry'),
137
+ onPress: () => {
138
+ DialogManager.dismiss()
139
+ onRetry?.()
140
+ e?.remove()
141
+ },
142
+ })
143
+ }
144
+ show({
145
+ title: title,
146
+ content: message,
147
+ clickBackdropDismiss: false,
148
+ actions,
149
+ })
150
+ }
151
+
152
+ export const show = ({ actions, clickBackdropDismiss, content, title }: IDialogShowConfig, callback: () => void = () => { }) => {
153
+ const titleElement = title !== undefined ?
154
+ <DialogTitle
155
+ title={title}
156
+ /> :
157
+ undefined
158
+
159
+ const contentElement = typeof content === 'string' ? (
160
+ <Text>
161
+ {content}
162
+ </Text>
163
+ ) : content
164
+
165
+ const onClickBackdrop = () => {
166
+ if (clickBackdropDismiss) {
167
+ DialogManager.dismiss()
168
+ }
169
+ }
170
+
171
+ let footerElement
172
+ if (actions !== undefined && actions.length > 0) {
173
+ footerElement = (
174
+ <DialogFooter
175
+ style={{
176
+ padding: 10,
177
+ justifyContent: 'flex-end',
178
+ }}
179
+ >
180
+ {actions.map(({ buttonStyle= {}, isCancel, label, onPress, textStyle }, index) => {
181
+ const _buttonStyle = Object.assign(buttonStyle, index > 0 ? { marginLeft: 10 } : {})
182
+
183
+ return (
184
+ <DialogButton
185
+ key={`button${index}`}
186
+ // label={label}
187
+ // mode={'contained'}
188
+ // onPress={onPress}
189
+ // labelStyle={{
190
+ // // color: '#000',
191
+ // }}
192
+ isCancel={isCancel}
193
+ text={label}
194
+ onPress={() => {
195
+ onPress()
196
+ }}
197
+ type={'round'}
198
+ textStyle={textStyle}
199
+ style={_buttonStyle}
200
+ />
201
+ )
202
+ })}
203
+ </DialogFooter>
204
+ )
205
+ }
206
+
207
+ DialogManager.show({
208
+ width: 0.8,
209
+ visible: true,
210
+ modalTitle: titleElement,
211
+ children: (
212
+ <DialogContent>
213
+ {contentElement}
214
+ </DialogContent>
215
+ ),
216
+ footer: footerElement,
217
+ onTouchOutside: onClickBackdrop,
218
+ }, () => {
219
+ // callback on show
220
+ })
221
+ }
222
+
223
+ export const dismiss = (callback: () => void|Promise<void> = () => { }) => {
224
+ DialogManager.dismiss(() => {
225
+ // dismiss callback
226
+ void callback()
227
+ })
228
+ }
229
+
230
+ export const dismissAll = (callback: () => void |Promise<void>= () => { }) => {
231
+ DialogManager.dismissAll(() => {
232
+ // dismiss callback
233
+ void callback()
234
+ })
235
+ }
236
+
237
+ const Dialog = {
238
+ confirm,
239
+ info,
240
+ show,
241
+ dismiss,
242
+ dismissAll,
243
+ apiError,
244
+ }
245
+
246
+ export default Dialog
@@ -0,0 +1,110 @@
1
+ import * as momont from 'moment'
2
+ import React from 'react'
3
+ import RootSiblings from 'react-native-root-siblings'
4
+
5
+ import logger from '@/infrastructures/common/logger'
6
+ import Timeout from '@/infrastructures/common/Timeout'
7
+
8
+ import { BaseDialog, Handle as Dialog } from './components/BaseDialog'
9
+ // import Dialog from './Dialog';
10
+ import type { DialogProps } from './type'
11
+
12
+ const DESTROY_TIMEOUT: number = 500
13
+
14
+
15
+ class Manager {
16
+
17
+ dialogs: RootSiblings[]
18
+ dialogsRef: Dialog[]
19
+ constructor() {
20
+ this.dialogs = []
21
+ this.dialogsRef = []
22
+ }
23
+
24
+ get currentDialog() {
25
+ return this.dialogs[this.dialogs.length - 1]
26
+ }
27
+
28
+ addRef = (ref: Dialog) => {
29
+ this.dialogsRef.push(ref)
30
+ }
31
+
32
+ add = (props: DialogProps, callback: () => void): void => {
33
+
34
+ const dialog = new RootSiblings(
35
+ <BaseDialog
36
+ ref={(ref) => {
37
+ if (ref) {
38
+ this.addRef(ref)
39
+ }
40
+ }}
41
+ {...props}
42
+ />,
43
+ callback)
44
+ // dialog.id = momont().getTimestamp()
45
+ this.dialogs.push(dialog)
46
+ }
47
+
48
+ destroy(): void {
49
+ const dialog = this.dialogs.pop()
50
+ logger.log('destroy dialog')
51
+ setTimeout(() => {
52
+ dialog?.destroy()
53
+ }, DESTROY_TIMEOUT)
54
+ }
55
+
56
+ onDialogDismissed = (onDismissed: () => void = () => {}): void => {
57
+ onDismissed()
58
+ this.destroy()
59
+ }
60
+
61
+ update = (props: DialogProps, callback: () => void = () => {}): void => {
62
+ this.currentDialog.update(
63
+ (
64
+ <BaseDialog
65
+ {...props}
66
+ />
67
+ ),
68
+ callback,
69
+ )
70
+ }
71
+
72
+ show = (props: DialogProps, callback: () => void = () => {}): void => {
73
+ this.add({
74
+ ...props,
75
+ visible: true,
76
+ }, callback)
77
+ }
78
+
79
+ dismiss = (callback: () => void = () => {}): void => {
80
+ // this.update({
81
+ // visible: false,
82
+ // }, callback);
83
+ logger.log('dialogmanager dismiss')
84
+ const d = this.dialogsRef.pop()
85
+ const onDismissed = () => {
86
+ this.destroy()
87
+ const timeout = new Timeout<string>({ ms: DESTROY_TIMEOUT/2 })
88
+ void timeout.start()
89
+ .catch(() => {
90
+ // timeout
91
+ })
92
+ .finally(() => {
93
+ callback()
94
+ })
95
+ }
96
+ if (d) {
97
+ d.dismiss(onDismissed)
98
+ } else {
99
+ onDismissed()
100
+ }
101
+ }
102
+
103
+ dismissAll = (callback: () => void = () => {}): void => {
104
+ this.dialogs.forEach(() => {
105
+ this.dismiss(callback)
106
+ })
107
+ }
108
+ }
109
+
110
+ export default Manager
@@ -0,0 +1,29 @@
1
+ import { Animated } from 'react-native'
2
+
3
+ export type AnimationConfig = {
4
+ initialValue?: number
5
+ useNativeDriver?: boolean
6
+ }
7
+
8
+ // Base Animation class
9
+ export default class Animation {
10
+ useNativeDriver: boolean
11
+ animate: Animated.Value
12
+
13
+ constructor({ initialValue = 0, useNativeDriver = true }: AnimationConfig = {}) {
14
+ this.animate = new Animated.Value(initialValue)
15
+ this.useNativeDriver = useNativeDriver
16
+ }
17
+
18
+ in(onFinished?: () => void): void {
19
+ throw Error('not implemented yet')
20
+ }
21
+
22
+ out(onFinished?: () => void): void {
23
+ throw Error('not implemented yet')
24
+ }
25
+
26
+ getAnimations(): Record<string, unknown> {
27
+ throw Error('not implemented yet')
28
+ }
29
+ }
@@ -0,0 +1,40 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import { Animated } from 'react-native'
3
+
4
+ import Animation, { AnimationConfig } from './Animation'
5
+
6
+ type FadeAnimationConfig = AnimationConfig & {
7
+ animationDuration?: number
8
+ }
9
+
10
+ export default class FadeAnimation extends Animation {
11
+ animationDuration: number
12
+
13
+ constructor({ animationDuration = 200, initialValue = 0, useNativeDriver = false }: FadeAnimationConfig = {}) {
14
+ super({
15
+ initialValue,
16
+ useNativeDriver,
17
+ })
18
+ this.animationDuration = animationDuration
19
+ }
20
+
21
+ in(onFinished: () => void = () => {}): void {
22
+ Animated.timing(this.animate, {
23
+ toValue: 1,
24
+ duration: this.animationDuration,
25
+ useNativeDriver: this.useNativeDriver,
26
+ }).start(onFinished)
27
+ }
28
+
29
+ out(onFinished: () => void = () => {}): void {
30
+ Animated.timing(this.animate, {
31
+ toValue: 0,
32
+ duration: this.animationDuration,
33
+ useNativeDriver: this.useNativeDriver,
34
+ }).start(onFinished)
35
+ }
36
+
37
+ getAnimations(): Record<string, unknown> {
38
+ return { opacity: this.animate }
39
+ }
40
+ }
@@ -0,0 +1,37 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import { Animated } from 'react-native'
3
+
4
+ import Animation from './Animation'
5
+
6
+ export default class ScaleAnimation extends Animation {
7
+ in(onFinished: () => void = () => {}): void {
8
+ Animated.spring(this.animate, {
9
+ toValue: 1,
10
+ velocity: 0,
11
+ tension: 65,
12
+ friction: 7,
13
+ useNativeDriver: this.useNativeDriver,
14
+ }).start(onFinished)
15
+ }
16
+
17
+ out(onFinished: () => void = () => {}): void {
18
+ Animated.timing(this.animate, {
19
+ toValue: 0,
20
+ duration: 200,
21
+ useNativeDriver: this.useNativeDriver,
22
+ }).start(onFinished)
23
+ }
24
+
25
+ getAnimations(): Record<string, unknown> {
26
+ return {
27
+ transform: [
28
+ {
29
+ scale: this.animate.interpolate({
30
+ inputRange: [0, 1],
31
+ outputRange: [0, 1],
32
+ }),
33
+ },
34
+ ],
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,89 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import { Animated, Dimensions } from 'react-native'
3
+
4
+ import Animation, { AnimationConfig } from './Animation'
5
+
6
+ const { height: SCREEN_HEIGHT, width: SCREEN_WIDTH } = Dimensions.get('window')
7
+
8
+ type SlideFrom = 'top' | 'bottom' | 'left' | 'right'
9
+ type SlideAnimationConfig = AnimationConfig & {
10
+ slideFrom?: SlideFrom
11
+ }
12
+
13
+ export default class SlideAnimation extends Animation {
14
+ slideFrom: SlideFrom
15
+
16
+ static SLIDE_FROM_TOP:SlideFrom = 'top'
17
+ static SLIDE_FROM_BOTTOM:SlideFrom = 'bottom'
18
+ static SLIDE_FROM_LEFT:SlideFrom = 'left'
19
+ static SLIDE_FROM_RIGHT:SlideFrom = 'right'
20
+
21
+ constructor({ initialValue = 0, useNativeDriver = true, slideFrom = SlideAnimation.SLIDE_FROM_BOTTOM }: SlideAnimationConfig = {}) {
22
+ super({
23
+ initialValue,
24
+ useNativeDriver,
25
+ })
26
+ this.slideFrom = slideFrom
27
+ }
28
+
29
+ in(onFinished: () => void = () => {}, options = {}): void {
30
+ Animated.spring(this.animate, {
31
+ toValue: 1,
32
+ velocity: 0,
33
+ tension: 65,
34
+ friction: 11,
35
+ useNativeDriver: this.useNativeDriver,
36
+ ...options,
37
+ }).start(onFinished)
38
+ }
39
+
40
+ out(onFinished: () => void = () => {}, options = {}): void {
41
+ Animated.spring(this.animate, {
42
+ toValue: 0,
43
+ velocity: 0,
44
+ tension: 65,
45
+ friction: 11,
46
+ useNativeDriver: this.useNativeDriver,
47
+ ...options,
48
+ }).start(onFinished)
49
+ }
50
+
51
+ getAnimations(): Record<string, unknown> {
52
+ const transform = []
53
+ if (this.slideFrom === SlideAnimation.SLIDE_FROM_TOP) {
54
+ transform.push({
55
+ translateY: this.animate.interpolate({
56
+ inputRange: [0, 1],
57
+ outputRange: [-SCREEN_HEIGHT, 0],
58
+ }),
59
+ })
60
+ } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_BOTTOM) {
61
+ transform.push({
62
+ translateY: this.animate.interpolate({
63
+ inputRange: [0, 1],
64
+ outputRange: [SCREEN_HEIGHT, 0],
65
+ }),
66
+ })
67
+ } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_LEFT) {
68
+ transform.push({
69
+ translateX: this.animate.interpolate({
70
+ inputRange: [0, 1],
71
+ outputRange: [-SCREEN_WIDTH, 0],
72
+ }),
73
+ })
74
+ } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_RIGHT) {
75
+ transform.push({
76
+ translateX: this.animate.interpolate({
77
+ inputRange: [0, 1],
78
+ outputRange: [SCREEN_WIDTH, 0],
79
+ }),
80
+ })
81
+ } else {
82
+ throw new Error(`
83
+ slideFrom: ${this.slideFrom} not supported. 'slideFrom' must be 'top' | 'bottom' | 'left' | 'right'
84
+ `)
85
+ }
86
+
87
+ return { transform }
88
+ }
89
+ }
@@ -0,0 +1,60 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ import React, { Component } from 'react'
3
+ import { Animated, StyleSheet, TouchableOpacity } from 'react-native'
4
+
5
+ import { PressableOpacity } from '@/components/basic'
6
+
7
+ import type { BackdropProps } from '../type'
8
+
9
+ export default class Backdrop extends Component<BackdropProps> {
10
+ static defaultProps = {
11
+ backgroundColor: '#000',
12
+ opacity: 0.5,
13
+ animationDuration: 2000,
14
+ visible: false,
15
+ useNativeDriver: true,
16
+ onPress: () => { },
17
+ }
18
+
19
+ componentDidUpdate(prevProps: BackdropProps) {
20
+ const {
21
+ animationDuration: duration, opacity, useNativeDriver, visible,
22
+ } = this.props
23
+ if (prevProps.visible !== visible) {
24
+ const toValue = visible ? opacity : 0
25
+ Animated.timing(this.opacity, {
26
+ toValue,
27
+ duration,
28
+ useNativeDriver: useNativeDriver === undefined ? false : useNativeDriver,
29
+ }).start()
30
+ }
31
+ }
32
+
33
+ setOpacity = (value: number) => {
34
+ this.opacity.setValue(value)
35
+ }
36
+
37
+ opacity = new Animated.Value(0)
38
+
39
+ render() {
40
+ const { backgroundColor, onPress, pointerEvents } = this.props
41
+ const { opacity } = this
42
+
43
+ return (
44
+ <Animated.View
45
+ pointerEvents={pointerEvents}
46
+ style={[
47
+ StyleSheet.absoluteFill, {
48
+ backgroundColor,
49
+ opacity,
50
+ },
51
+ ]}
52
+ >
53
+ <PressableOpacity
54
+ onPress={onPress}
55
+ style={StyleSheet.absoluteFill}
56
+ />
57
+ </Animated.View>
58
+ )
59
+ }
60
+ }