@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.
- package/.github/workflows/npm-publish.yml +28 -0
- package/.vscode/settings.json +15 -0
- package/README.md +58 -0
- package/package.json +16 -0
- package/template/.bundle/config +2 -0
- package/template/.env.development +1 -0
- package/template/.env.production +1 -0
- package/template/.eslintrc.js +392 -0
- package/template/.java-version +1 -0
- package/template/.prettierrc.js +5 -0
- package/template/.ruby-version +1 -0
- package/template/.watchmanconfig +1 -0
- package/template/Gemfile +23 -0
- package/template/Gemfile.lock +330 -0
- package/template/README.md +97 -0
- package/template/ReactotronConfig.js +17 -0
- package/template/__tests__/App.test.tsx +13 -0
- package/template/_gitignore +75 -0
- package/template/_node-version +1 -0
- package/template/android/app/build.gradle +162 -0
- package/template/android/app/debug.keystore +0 -0
- package/template/android/app/proguard-rules.pro +10 -0
- package/template/android/app/src/debug/AndroidManifest.xml +9 -0
- package/template/android/app/src/main/AndroidManifest.xml +26 -0
- package/template/android/app/src/main/java/com/projectname/MainActivity.kt +30 -0
- package/template/android/app/src/main/java/com/projectname/MainApplication.kt +27 -0
- package/template/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
- package/template/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/template/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/template/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/template/android/app/src/main/res/values/strings.xml +3 -0
- package/template/android/app/src/main/res/values/styles.xml +9 -0
- package/template/android/build.gradle +37 -0
- package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/template/android/gradle.properties +48 -0
- package/template/android/gradlew +251 -0
- package/template/android/gradlew.bat +99 -0
- package/template/android/keystore/keystore.properties +4 -0
- package/template/android/settings.gradle +6 -0
- package/template/android/version.properties +2 -0
- package/template/app.json +4 -0
- package/template/babel.config.js +38 -0
- package/template/fastlane/Fastfile +136 -0
- package/template/fastlane/Pluginfile +9 -0
- package/template/fastlane/README.md +46 -0
- package/template/index.js +9 -0
- package/template/ios/.xcode.env +11 -0
- package/template/ios/Podfile +35 -0
- package/template/ios/Podfile.lock +3669 -0
- package/template/ios/ProjectName/AppDelegate.swift +48 -0
- package/template/ios/ProjectName/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/template/ios/ProjectName/Images.xcassets/Contents.json +6 -0
- package/template/ios/ProjectName/Info.plist +66 -0
- package/template/ios/ProjectName/LaunchScreen.storyboard +47 -0
- package/template/ios/ProjectName/PrivacyInfo.xcprivacy +47 -0
- package/template/ios/ProjectName.xcodeproj/project.pbxproj +482 -0
- package/template/ios/ProjectName.xcodeproj/xcshareddata/xcschemes/ProjectName.xcscheme +88 -0
- package/template/ios/ProjectName.xcworkspace/contents.xcworkspacedata +10 -0
- package/template/jest.config.js +3 -0
- package/template/metro.config.js +20 -0
- package/template/package-lock.json +17073 -0
- package/template/package.json +156 -0
- package/template/src/@types/emotion.d.ts +12 -0
- package/template/src/@types/env.d.ts +3 -0
- package/template/src/@types/redux-persist-transform-immutable.d.ts +1 -0
- package/template/src/@types/typing.d.ts +17 -0
- package/template/src/AppContainer.tsx +109 -0
- package/template/src/assets/images/143.png +0 -0
- package/template/src/assets/index.ts +13 -0
- package/template/src/components/basic/BackButton/index.tsx +34 -0
- package/template/src/components/basic/Body/index.tsx +68 -0
- package/template/src/components/basic/Button/index.tsx +181 -0
- package/template/src/components/basic/Button/utils.ts +78 -0
- package/template/src/components/basic/ButtonGroup/index.tsx +182 -0
- package/template/src/components/basic/Card/index.tsx +3 -0
- package/template/src/components/basic/Container/index.tsx +38 -0
- package/template/src/components/basic/Content/index.tsx +87 -0
- package/template/src/components/basic/DropDown/index.tsx +354 -0
- package/template/src/components/basic/ExpandableOverlay/index.tsx +113 -0
- package/template/src/components/basic/Header/index.tsx +216 -0
- package/template/src/components/basic/Header/styles.ts +0 -0
- package/template/src/components/basic/Icons/index.tsx +131 -0
- package/template/src/components/basic/InputLabel/index.tsx +19 -0
- package/template/src/components/basic/LoadingOverlay/index.tsx +68 -0
- package/template/src/components/basic/MaterialTextInput/index.tsx +153 -0
- package/template/src/components/basic/NumberInput/index.tsx +53 -0
- package/template/src/components/basic/Picker/PickerContext.ts +7 -0
- package/template/src/components/basic/Picker/PickerHeader.tsx +130 -0
- package/template/src/components/basic/Picker/PickerItem.tsx +105 -0
- package/template/src/components/basic/Picker/PickerItemsList.tsx +135 -0
- package/template/src/components/basic/Picker/PickerPresenter.ts +54 -0
- package/template/src/components/basic/Picker/hooks/useImperativePickerHandle.ts +27 -0
- package/template/src/components/basic/Picker/hooks/usePickerLabel.ts +74 -0
- package/template/src/components/basic/Picker/hooks/usePickerSearch.ts +37 -0
- package/template/src/components/basic/Picker/hooks/usePickerSelection.ts +57 -0
- package/template/src/components/basic/Picker/index.tsx +284 -0
- package/template/src/components/basic/Picker/types.tsx +229 -0
- package/template/src/components/basic/PressableOpacity/index.tsx +20 -0
- package/template/src/components/basic/RootDialog/Dialog.tsx +246 -0
- package/template/src/components/basic/RootDialog/Manager.tsx +110 -0
- package/template/src/components/basic/RootDialog/animations/Animation.ts +29 -0
- package/template/src/components/basic/RootDialog/animations/FadeAnimation.ts +40 -0
- package/template/src/components/basic/RootDialog/animations/ScaleAnimation.ts +37 -0
- package/template/src/components/basic/RootDialog/animations/SlideAnimation.ts +89 -0
- package/template/src/components/basic/RootDialog/components/Backdrop.tsx +60 -0
- package/template/src/components/basic/RootDialog/components/BaseDialog.tsx +564 -0
- package/template/src/components/basic/RootDialog/components/BottomDialog.tsx +32 -0
- package/template/src/components/basic/RootDialog/components/DialogButton.tsx +87 -0
- package/template/src/components/basic/RootDialog/components/DialogContent.tsx +26 -0
- package/template/src/components/basic/RootDialog/components/DialogContext.tsx +8 -0
- package/template/src/components/basic/RootDialog/components/DialogFooter.tsx +42 -0
- package/template/src/components/basic/RootDialog/components/DialogTitle.tsx +53 -0
- package/template/src/components/basic/RootDialog/components/DraggableView.tsx +271 -0
- package/template/src/components/basic/RootDialog/index.ts +21 -0
- package/template/src/components/basic/RootDialog/type.ts +102 -0
- package/template/src/components/basic/Text/index.tsx +8 -0
- package/template/src/components/basic/index.ts +35 -0
- package/template/src/configs/constants/type/APIStatus.type.ts +8 -0
- package/template/src/configs/constants/type/Locale.type.ts +7 -0
- package/template/src/configs/constants/type/StorageKey.type.ts +7 -0
- package/template/src/configs/constants/type/ThemeType.type.ts +6 -0
- package/template/src/configs/constants/type/index.ts +11 -0
- package/template/src/configs/index.ts +22 -0
- package/template/src/contexts/ThemeContext.ts +6 -0
- package/template/src/hooks/useAppLoading.ts +26 -0
- package/template/src/hooks/useAppState.ts +36 -0
- package/template/src/hooks/useArray.ts +47 -0
- package/template/src/hooks/useAsync.ts +42 -0
- package/template/src/hooks/useAsyncStorage.ts +41 -0
- package/template/src/hooks/useBoolean.ts +21 -0
- package/template/src/hooks/useBuildTheme.ts +249 -0
- package/template/src/hooks/useCountDown.ts +111 -0
- package/template/src/hooks/useCounter.ts +27 -0
- package/template/src/hooks/useDebounce.ts +25 -0
- package/template/src/hooks/useDebouncedValidate.ts +32 -0
- package/template/src/hooks/useDebugInformation.ts +38 -0
- package/template/src/hooks/useDeviceToken.ts +20 -0
- package/template/src/hooks/useEncryptedStorage.ts +41 -0
- package/template/src/hooks/useFontFamily.ts +13 -0
- package/template/src/hooks/useHttp.ts +18 -0
- package/template/src/hooks/useInterval.ts +24 -0
- package/template/src/hooks/useIsForeground.ts +17 -0
- package/template/src/hooks/useMMKVStorage.ts +0 -0
- package/template/src/hooks/usePrevious.ts +12 -0
- package/template/src/hooks/useRenderCount.ts +10 -0
- package/template/src/hooks/useTheme.ts +17 -0
- package/template/src/hooks/useTimeCountDown.ts +91 -0
- package/template/src/index.tsx +65 -0
- package/template/src/infrastructures/NetClient/AbstractClient.ts +66 -0
- package/template/src/infrastructures/NetClient/ApiResponse.ts +16 -0
- package/template/src/infrastructures/NetClient/ApisauceClient.ts +76 -0
- package/template/src/infrastructures/NetClient/AxiosClient.ts +80 -0
- package/template/src/infrastructures/NetClient/FetchNetClient.ts +120 -0
- package/template/src/infrastructures/NetClient/config.ts +3 -0
- package/template/src/infrastructures/NetClient/interfaces/INetClient.ts +6 -0
- package/template/src/infrastructures/Storage/IStorage.ts +7 -0
- package/template/src/infrastructures/Storage/MMKVStorage.ts +41 -0
- package/template/src/infrastructures/common/Timeout.ts +27 -0
- package/template/src/infrastructures/common/colorUtils.ts +82 -0
- package/template/src/infrastructures/common/dateUtils.ts +39 -0
- package/template/src/infrastructures/common/logger.ts +115 -0
- package/template/src/locales/en-US/general.json +26 -0
- package/template/src/locales/en-US/index.ts +9 -0
- package/template/src/locales/en-US/screens.json +4 -0
- package/template/src/locales/en-US/setting.json +3 -0
- package/template/src/locales/i18n.ts +109 -0
- package/template/src/locales/zh-TW/general.json +26 -0
- package/template/src/locales/zh-TW/index.ts +9 -0
- package/template/src/locales/zh-TW/screens.json +4 -0
- package/template/src/locales/zh-TW/setting.json +3 -0
- package/template/src/models/index.ts +5 -0
- package/template/src/models/request.model.ts +50 -0
- package/template/src/navigators/DrawerNav/DrawerContent.tsx +66 -0
- package/template/src/navigators/DrawerNav/DrawerItem.tsx +261 -0
- package/template/src/navigators/DrawerNav/index.tsx +39 -0
- package/template/src/navigators/DrawerNav/props.ts +12 -0
- package/template/src/navigators/DrawerNav/types.ts +8 -0
- package/template/src/navigators/MainBottomTabNav/index.tsx +83 -0
- package/template/src/navigators/MainBottomTabNav/props.ts +16 -0
- package/template/src/navigators/MainBottomTabNav/types.ts +6 -0
- package/template/src/navigators/RootStack.tsx +43 -0
- package/template/src/navigators/index.tsx +40 -0
- package/template/src/navigators/props.ts +14 -0
- package/template/src/navigators/types.ts +18 -0
- package/template/src/navigators/utils.ts +68 -0
- package/template/src/redux/api/api.ts +41 -0
- package/template/src/redux/reducers/appSlice.ts +26 -0
- package/template/src/redux/reducers/index.ts +21 -0
- package/template/src/redux/reducers/nonPersistSlice.ts +51 -0
- package/template/src/redux/reducers/settingSlice.ts +48 -0
- package/template/src/redux/reducers/themeSlice.ts +55 -0
- package/template/src/redux/saga/index.ts +5 -0
- package/template/src/redux/saga/settingSaga.ts +21 -0
- package/template/src/redux/selectors/app.ts +9 -0
- package/template/src/redux/selectors/nonPersist.ts +23 -0
- package/template/src/redux/selectors/setting.ts +29 -0
- package/template/src/redux/selectors/theme.ts +13 -0
- package/template/src/redux/store/index.ts +79 -0
- package/template/src/redux/store/types.d.ts +5 -0
- package/template/src/screens/Home/index.tsx +146 -0
- package/template/src/screens/Settings/components/Item.tsx +45 -0
- package/template/src/screens/Settings/index.tsx +97 -0
- package/template/src/screens/Splash/index.tsx +53 -0
- package/template/src/services/Dialogs.tsx +226 -0
- package/template/src/services/PermissionCheck.ts +257 -0
- package/template/src/theme/Common.ts +48 -0
- package/template/src/theme/Fonts.ts +196 -0
- package/template/src/theme/Gutters.ts +63 -0
- package/template/src/theme/Icons.ts +28 -0
- package/template/src/theme/Images.ts +13 -0
- package/template/src/theme/Layout.ts +106 -0
- package/template/src/theme/Variables.ts +167 -0
- package/template/src/theme/components/Buttons.ts +37 -0
- package/template/src/theme/index.ts +8 -0
- package/template/src/theme/metrics.ts +57 -0
- package/template/src/theme/themes/default_dark/Images.ts +7 -0
- package/template/src/theme/themes/default_dark/Variables.ts +84 -0
- package/template/src/theme/themes/default_dark/index.ts +2 -0
- package/template/src/theme/themes/index.ts +8 -0
- package/template/src/theme/types.ts +152 -0
- package/template/src/utils/encrypt-helper.ts +118 -0
- package/template/src/utils/index.ts +76 -0
- package/template/src/utils/sys-info-data.ts +17 -0
- package/template/tsconfig.json +44 -0
- package/template.config.js +8 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Route, useNavigation } from '@react-navigation/native'
|
|
2
|
+
import { StackNavigationProp } from '@react-navigation/stack'
|
|
3
|
+
import React, { useCallback, useEffect } from 'react'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
5
|
+
import useState from 'react-usestateref'
|
|
6
|
+
|
|
7
|
+
import useTheme from '@/hooks/useTheme'
|
|
8
|
+
import logger from '@/infrastructures/common/logger'
|
|
9
|
+
import Timeout from '@/infrastructures/common/Timeout'
|
|
10
|
+
import { RootScreenNavigationProp } from '@/navigators/props'
|
|
11
|
+
import { AppRoutes } from '@/navigators/types'
|
|
12
|
+
import { navigateAndSimpleReset } from '@/navigators/utils'
|
|
13
|
+
import { setDefaultTheme } from '@/redux/reducers/themeSlice'
|
|
14
|
+
import { useAppDispatch } from '@/redux/store'
|
|
15
|
+
import { FontScale } from '@/theme/types'
|
|
16
|
+
|
|
17
|
+
const SplashScreen = () => {
|
|
18
|
+
const navigation = useNavigation<RootScreenNavigationProp>()
|
|
19
|
+
const { t } = useTranslation()
|
|
20
|
+
const dispatch = useAppDispatch()
|
|
21
|
+
const [timeout, setTimeout] = useState(false)
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
init()
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
const init = () => {
|
|
28
|
+
dispatch(setDefaultTheme({
|
|
29
|
+
theme: 'default',
|
|
30
|
+
darkMode: null,
|
|
31
|
+
fontScale: FontScale.MEDIUM,
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
const to = new Timeout({ ms: 3000 })
|
|
35
|
+
to.start().catch(() => {
|
|
36
|
+
setTimeout(true)
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
// init whether completed
|
|
42
|
+
if (timeout) {
|
|
43
|
+
// Navigate to Main Drawer
|
|
44
|
+
navigateAndSimpleReset(AppRoutes.MainDrawerNav)
|
|
45
|
+
}
|
|
46
|
+
}, [timeout])
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<></>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default SplashScreen
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { BackHandler, TextStyle, ViewStyle } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import { Text } from '@/components/basic'
|
|
5
|
+
import DialogManager, { Dialog, DialogButton, DialogContent, DialogFooter, DialogTitle } from '@/components/basic/RootDialog'
|
|
6
|
+
import logger from '@/infrastructures/common/logger'
|
|
7
|
+
import i18n from '@/locales/i18n'
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
interface IDialogAction {
|
|
11
|
+
label: string
|
|
12
|
+
onPress: () => void
|
|
13
|
+
buttonStyle?: ViewStyle
|
|
14
|
+
textStyle?: TextStyle
|
|
15
|
+
isCancel?: boolean
|
|
16
|
+
}
|
|
17
|
+
interface IDialogShowConfig {
|
|
18
|
+
title?: string
|
|
19
|
+
content: string | React.ReactElement
|
|
20
|
+
actions?: IDialogAction[]
|
|
21
|
+
clickBackdropDismiss?: boolean
|
|
22
|
+
}
|
|
23
|
+
interface IDialogConfirmConfig extends Omit<IDialogShowConfig, 'actions'> {
|
|
24
|
+
confirmText?: string
|
|
25
|
+
onConfirm?: () => void
|
|
26
|
+
onCancel?: () => void
|
|
27
|
+
}
|
|
28
|
+
interface IDialogInfoConfig extends Omit<IDialogShowConfig, 'actions'> {
|
|
29
|
+
confirmText?: string
|
|
30
|
+
onConfirm?: () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface IDialogApiErrorConfig {
|
|
34
|
+
title?: string
|
|
35
|
+
message: string
|
|
36
|
+
onCancel?: () => void
|
|
37
|
+
allowRetry: boolean
|
|
38
|
+
onRetry?: () => unknown
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const confirm = ({
|
|
42
|
+
clickBackdropDismiss,
|
|
43
|
+
confirmText,
|
|
44
|
+
content,
|
|
45
|
+
onCancel,
|
|
46
|
+
onConfirm,
|
|
47
|
+
title,
|
|
48
|
+
}: IDialogConfirmConfig) => {
|
|
49
|
+
const { t } = i18n
|
|
50
|
+
const e = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
51
|
+
return true
|
|
52
|
+
})
|
|
53
|
+
show({
|
|
54
|
+
title,
|
|
55
|
+
content,
|
|
56
|
+
clickBackdropDismiss,
|
|
57
|
+
actions: [
|
|
58
|
+
{
|
|
59
|
+
label: t('general:button.cancel'),
|
|
60
|
+
onPress: () => {
|
|
61
|
+
DialogManager.dismiss()
|
|
62
|
+
onCancel?.()
|
|
63
|
+
e?.remove()
|
|
64
|
+
},
|
|
65
|
+
isCancel: true,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: confirmText || t('general:button.confirm'),
|
|
69
|
+
onPress: () => {
|
|
70
|
+
DialogManager.dismiss()
|
|
71
|
+
onConfirm?.()
|
|
72
|
+
e?.remove()
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const info = ({ clickBackdropDismiss, confirmText, content, onConfirm, title }: IDialogInfoConfig) => {
|
|
80
|
+
const { t } = i18n
|
|
81
|
+
const e = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
82
|
+
return true
|
|
83
|
+
})
|
|
84
|
+
show({
|
|
85
|
+
title,
|
|
86
|
+
content,
|
|
87
|
+
clickBackdropDismiss,
|
|
88
|
+
actions: [
|
|
89
|
+
{
|
|
90
|
+
label: confirmText || t('general:button.confirm'),
|
|
91
|
+
onPress: () => {
|
|
92
|
+
logger.log('info dialog pressed confirm')
|
|
93
|
+
DialogManager.dismiss()
|
|
94
|
+
onConfirm?.()
|
|
95
|
+
e?.remove()
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const apiError = ({ allowRetry, message, onCancel, onRetry, title }: IDialogApiErrorConfig) => {
|
|
103
|
+
const { t } = i18n
|
|
104
|
+
const e = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
105
|
+
return true
|
|
106
|
+
})
|
|
107
|
+
const actions: IDialogAction[] = [
|
|
108
|
+
{
|
|
109
|
+
label: t('general:button.cancel'),
|
|
110
|
+
onPress: () => {
|
|
111
|
+
DialogManager.dismiss()
|
|
112
|
+
onCancel?.()
|
|
113
|
+
e?.remove()
|
|
114
|
+
},
|
|
115
|
+
isCancel: true,
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
if (allowRetry) {
|
|
119
|
+
actions.push({
|
|
120
|
+
label: t('general:button.retry'),
|
|
121
|
+
onPress: () => {
|
|
122
|
+
DialogManager.dismiss()
|
|
123
|
+
onRetry?.()
|
|
124
|
+
e?.remove()
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
show({
|
|
129
|
+
title: title,
|
|
130
|
+
content: message,
|
|
131
|
+
clickBackdropDismiss: false,
|
|
132
|
+
actions,
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const show = ({ actions, clickBackdropDismiss, content, title }: IDialogShowConfig, callback: () => void = () => { }) => {
|
|
137
|
+
const titleElement = title !== undefined ?
|
|
138
|
+
<DialogTitle
|
|
139
|
+
title={title}
|
|
140
|
+
/> :
|
|
141
|
+
undefined
|
|
142
|
+
|
|
143
|
+
const contentElement = typeof content === 'string' ? (
|
|
144
|
+
<Text>
|
|
145
|
+
{content}
|
|
146
|
+
</Text>
|
|
147
|
+
) : content
|
|
148
|
+
|
|
149
|
+
const onClickBackdrop = () => {
|
|
150
|
+
if (clickBackdropDismiss) {
|
|
151
|
+
DialogManager.dismiss()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let footerElement
|
|
156
|
+
if (actions !== undefined && actions.length > 0) {
|
|
157
|
+
footerElement = (
|
|
158
|
+
<DialogFooter
|
|
159
|
+
style={{
|
|
160
|
+
padding: 10,
|
|
161
|
+
justifyContent: 'flex-end',
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{actions.map(({ buttonStyle= {}, isCancel, label, onPress, textStyle }, index) => {
|
|
165
|
+
const _buttonStyle = Object.assign(buttonStyle, index > 0 ? { marginLeft: 10 } : {})
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<DialogButton
|
|
169
|
+
key={`button${index}`}
|
|
170
|
+
isCancel={isCancel}
|
|
171
|
+
text={label}
|
|
172
|
+
onPress={() => {
|
|
173
|
+
onPress()
|
|
174
|
+
}}
|
|
175
|
+
type={'round'}
|
|
176
|
+
textStyle={textStyle}
|
|
177
|
+
style={_buttonStyle}
|
|
178
|
+
/>
|
|
179
|
+
)
|
|
180
|
+
})}
|
|
181
|
+
</DialogFooter>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
DialogManager.show({
|
|
186
|
+
width: 0.8,
|
|
187
|
+
visible: true,
|
|
188
|
+
modalTitle: titleElement,
|
|
189
|
+
children: (
|
|
190
|
+
<DialogContent>
|
|
191
|
+
{contentElement}
|
|
192
|
+
</DialogContent>
|
|
193
|
+
),
|
|
194
|
+
footer: footerElement,
|
|
195
|
+
onTouchOutside: onClickBackdrop,
|
|
196
|
+
}, () => {
|
|
197
|
+
// callback on show
|
|
198
|
+
if (callback) callback()
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const dismiss = (callback: () => void|Promise<void> = () => { }) => {
|
|
203
|
+
DialogManager.dismiss(() => {
|
|
204
|
+
// dismiss callback
|
|
205
|
+
void callback()
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const dismissAll = (callback: () => void |Promise<void>= () => { }) => {
|
|
210
|
+
DialogManager.dismissAll(() => {
|
|
211
|
+
// dismiss callback
|
|
212
|
+
void callback()
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const Dialogs = {
|
|
217
|
+
confirm,
|
|
218
|
+
info,
|
|
219
|
+
show,
|
|
220
|
+
dismiss,
|
|
221
|
+
dismissAll,
|
|
222
|
+
apiError,
|
|
223
|
+
}
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
export default Dialog
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Platform, Text } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
check,
|
|
5
|
+
Permission,
|
|
6
|
+
PERMISSIONS,
|
|
7
|
+
PermissionStatus,
|
|
8
|
+
request,
|
|
9
|
+
RESULTS,
|
|
10
|
+
} from 'react-native-permissions'
|
|
11
|
+
|
|
12
|
+
import logger from '@/infrastructures/common/logger'
|
|
13
|
+
import i18n from '@/locales/i18n'
|
|
14
|
+
import Dialogs from '@/services/Dialogs'
|
|
15
|
+
|
|
16
|
+
export type PermissionResult = PermissionStatus
|
|
17
|
+
|
|
18
|
+
const LocationPermission = Platform.OS === 'ios' ?
|
|
19
|
+
PERMISSIONS.IOS.LOCATION_WHEN_IN_USE :
|
|
20
|
+
PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
|
|
21
|
+
const CameraPermission = Platform.OS === 'ios' ?
|
|
22
|
+
PERMISSIONS.IOS.CAMERA :
|
|
23
|
+
PERMISSIONS.ANDROID.CAMERA
|
|
24
|
+
const PhotoPermission = Platform.OS === 'ios' ?
|
|
25
|
+
PERMISSIONS.IOS.PHOTO_LIBRARY :
|
|
26
|
+
Platform.OS === 'android' && Platform.Version >= 33 ?
|
|
27
|
+
PERMISSIONS.ANDROID.READ_MEDIA_IMAGES : PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE
|
|
28
|
+
|
|
29
|
+
export interface IPermissionCheckCallbacks {
|
|
30
|
+
onBlockedPermissionSetting: () => void|Promise<void>
|
|
31
|
+
onAllowPermissionRequest: (result: PermissionResult) => void|Promise<void>
|
|
32
|
+
onCancelPermissionRequest: () => void|Promise<void>
|
|
33
|
+
onUnavailablePermissionSetting: () => void|Promise<void>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PermissionType = 'location'|'camera'|'photo'|'push_notification'
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PermissionCheck {
|
|
40
|
+
|
|
41
|
+
private static _getPermissionName = (type: PermissionType) => {
|
|
42
|
+
switch (type) {
|
|
43
|
+
case 'location':
|
|
44
|
+
return LocationPermission
|
|
45
|
+
case 'camera':
|
|
46
|
+
return CameraPermission
|
|
47
|
+
case 'photo':
|
|
48
|
+
return PhotoPermission
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
static checkPermission = async (type: PermissionType, explain: boolean, callbacks: IPermissionCheckCallbacks) => {
|
|
52
|
+
return new Promise<PermissionStatus>((resolve) => {
|
|
53
|
+
const permissions = this._getPermissionName(type)
|
|
54
|
+
if (permissions === undefined) {
|
|
55
|
+
void callbacks.onUnavailablePermissionSetting()
|
|
56
|
+
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
void check(permissions).then((result) => {
|
|
60
|
+
logger.log(`checkForPermission ${type} - ${permissions}`, result)
|
|
61
|
+
switch (result) {
|
|
62
|
+
case RESULTS.LIMITED:
|
|
63
|
+
void callbacks.onAllowPermissionRequest(result)
|
|
64
|
+
break
|
|
65
|
+
case RESULTS.GRANTED:
|
|
66
|
+
void callbacks.onAllowPermissionRequest(result)
|
|
67
|
+
break
|
|
68
|
+
case RESULTS.UNAVAILABLE:
|
|
69
|
+
this._explainToUnavailablePermissionRequest(type, result, callbacks)
|
|
70
|
+
break
|
|
71
|
+
case RESULTS.BLOCKED:
|
|
72
|
+
if (explain) this._explainToBlockedPermissionRequest(type, result, callbacks)
|
|
73
|
+
break
|
|
74
|
+
case RESULTS.DENIED:
|
|
75
|
+
if (explain) {
|
|
76
|
+
this._explainToShowPermissionRequest(type, callbacks)
|
|
77
|
+
} else {
|
|
78
|
+
void this._requestPermissionCb(type, callbacks)
|
|
79
|
+
}
|
|
80
|
+
break
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private static _explainToUnavailablePermissionRequest = (type: PermissionType, result: PermissionStatus, callbacks: IPermissionCheckCallbacks) => {
|
|
87
|
+
Dialogs.confirm({
|
|
88
|
+
clickBackdropDismiss: false,
|
|
89
|
+
title: `${i18n.t('permission:'+type.toString()+'.permission_request_title_'+Platform.OS)}`,
|
|
90
|
+
content: `${i18n.t('permission:'+type.toString()+'.permission_blocked_'+Platform.OS)}`,
|
|
91
|
+
confirmText: `${i18n.t('permission:permission_setting')}`,
|
|
92
|
+
onCancel: () => {
|
|
93
|
+
void callbacks.onCancelPermissionRequest()
|
|
94
|
+
},
|
|
95
|
+
onConfirm: () => {
|
|
96
|
+
void callbacks.onUnavailablePermissionSetting()
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static _explainToBlockedPermissionRequest = (type: PermissionType, result: PermissionStatus, callbacks: IPermissionCheckCallbacks) => {
|
|
102
|
+
Dialogs.confirm({
|
|
103
|
+
clickBackdropDismiss: false,
|
|
104
|
+
title: `${i18n.t('permission:'+type.toString()+'.permission_request_title_'+Platform.OS)}`,
|
|
105
|
+
content: `${i18n.t('permission:'+type.toString()+'.permission_blocked_'+Platform.OS)}`,
|
|
106
|
+
confirmText: `${i18n.t('permission:permission_setting')}`,
|
|
107
|
+
onCancel: () => {
|
|
108
|
+
logger.log('explainToBlockedPermissionRequest onCancel')
|
|
109
|
+
void callbacks.onCancelPermissionRequest()
|
|
110
|
+
},
|
|
111
|
+
onConfirm: () => {
|
|
112
|
+
logger.log('explainToBlockedPermissionRequest onConfirm')
|
|
113
|
+
void callbacks.onBlockedPermissionSetting()
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private static _explainToShowPermissionRequest = (type: PermissionType, callbacks: IPermissionCheckCallbacks) => {
|
|
119
|
+
logger.log('explainToShowPermissionRequest')
|
|
120
|
+
Dialogs.confirm({
|
|
121
|
+
clickBackdropDismiss: false,
|
|
122
|
+
title: `${i18n.t('permission:'+type.toString()+'.permission_request_title_'+Platform.OS)}`,
|
|
123
|
+
content: `${i18n.t('permission:'+type.toString()+'.permission_request_message_'+Platform.OS)}`,
|
|
124
|
+
onCancel: () => {
|
|
125
|
+
logger.log('explainToShowPermissionRequest onCancel')
|
|
126
|
+
void callbacks.onCancelPermissionRequest()
|
|
127
|
+
},
|
|
128
|
+
onConfirm: () => {
|
|
129
|
+
logger.log('explainToShowPermissionRequest onConfirm')
|
|
130
|
+
void this._requestPermissionCb(type, callbacks)
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static _requestPermissionCb = async (type: PermissionType, callbacks: IPermissionCheckCallbacks) => {
|
|
136
|
+
const result = await this._requestPermission(type)
|
|
137
|
+
void callbacks.onAllowPermissionRequest(result)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static _requestPermission = async (type: PermissionType) => {
|
|
141
|
+
const permission = this._getPermissionName(type)
|
|
142
|
+
if (permission === undefined) {
|
|
143
|
+
|
|
144
|
+
return RESULTS.UNAVAILABLE
|
|
145
|
+
}
|
|
146
|
+
const result = await request(permission, {
|
|
147
|
+
title: i18n.t('permission:'+type.toString()+'.permission_request_title_'+Platform.OS),
|
|
148
|
+
message: i18n.t('permission:'+type.toString()+'.permission_request_message_'+Platform.OS),
|
|
149
|
+
buttonPositive: i18n.t('general:button.confirm'),
|
|
150
|
+
buttonNegative: `${i18n.t('general:button.cancel')}`,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
logger.log(`requestPermission ${type} result ${result}`)
|
|
154
|
+
|
|
155
|
+
return result
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
static checkLocationPermission = async (explain: boolean, callbacks: IPermissionCheckCallbacks) => {
|
|
161
|
+
return new Promise<PermissionStatus>((resolve) => {
|
|
162
|
+
|
|
163
|
+
void check(LocationPermission).then((result) => {
|
|
164
|
+
logger.log(`checkForLocationPermission ${result}`, explain)
|
|
165
|
+
switch (result) {
|
|
166
|
+
case RESULTS.GRANTED:
|
|
167
|
+
break
|
|
168
|
+
case RESULTS.UNAVAILABLE:
|
|
169
|
+
// user disable feature
|
|
170
|
+
this.explainToUnavailableLocationPermissionRequest(result, callbacks)
|
|
171
|
+
break
|
|
172
|
+
case RESULTS.BLOCKED:
|
|
173
|
+
// ask user to enable on setting
|
|
174
|
+
if (explain) this.explainToBlockedLocationPermissionRequest(result, callbacks)
|
|
175
|
+
break
|
|
176
|
+
case RESULTS.DENIED:
|
|
177
|
+
// request for permission
|
|
178
|
+
// result = await requestPermission(permissionToRequest);
|
|
179
|
+
if (explain) {
|
|
180
|
+
this.explainToShowLocationPermissionRequest(callbacks)
|
|
181
|
+
} else {
|
|
182
|
+
void this.requestLocationPermissionCb(callbacks)
|
|
183
|
+
}
|
|
184
|
+
break
|
|
185
|
+
}
|
|
186
|
+
resolve(result)
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static explainToUnavailableLocationPermissionRequest = (result: PermissionStatus, callbacks: IPermissionCheckCallbacks) => {
|
|
192
|
+
logger.log('explainToUnavailableLocationPermissionRequest result', result)
|
|
193
|
+
Dialogs.confirm({
|
|
194
|
+
clickBackdropDismiss: false,
|
|
195
|
+
title: `${i18n.t('permission:location_permission_request_title_'+Platform.OS)}`,
|
|
196
|
+
content: `${i18n.t('permission:location_permission_blocked_'+Platform.OS)}`,
|
|
197
|
+
confirmText: `${i18n.t('permission:permission_setting')}`,
|
|
198
|
+
onCancel: () => {
|
|
199
|
+
void callbacks.onUnavailablePermissionSetting()
|
|
200
|
+
},
|
|
201
|
+
onConfirm: () => {
|
|
202
|
+
void callbacks.onCancelPermissionRequest()
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static explainToBlockedLocationPermissionRequest = (result: PermissionStatus, callbacks: IPermissionCheckCallbacks) => {
|
|
208
|
+
logger.log('explainToBlockedLocationPermissionRequest result', result)
|
|
209
|
+
Dialogs.confirm({
|
|
210
|
+
clickBackdropDismiss: false,
|
|
211
|
+
title: `${i18n.t('permission:location_permission_request_title_'+Platform.OS)}`,
|
|
212
|
+
content: `${i18n.t('permission:location_permission_blocked_'+Platform.OS)}`,
|
|
213
|
+
confirmText: `${i18n.t('permission:permission_setting')}`,
|
|
214
|
+
onCancel: () => {
|
|
215
|
+
void callbacks.onBlockedPermissionSetting()
|
|
216
|
+
},
|
|
217
|
+
onConfirm: () => {
|
|
218
|
+
void callbacks.onCancelPermissionRequest()
|
|
219
|
+
},
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static explainToShowLocationPermissionRequest = (callbacks: IPermissionCheckCallbacks) => {
|
|
224
|
+
Dialogs.confirm({
|
|
225
|
+
clickBackdropDismiss: false,
|
|
226
|
+
title: `${i18n.t('permission:location_permission_request_title_'+Platform.OS)}`,
|
|
227
|
+
content: `${i18n.t('permission:location_permission_request_message_'+Platform.OS)}`,
|
|
228
|
+
onCancel: () => {
|
|
229
|
+
void callbacks.onCancelPermissionRequest()
|
|
230
|
+
},
|
|
231
|
+
onConfirm: () => {
|
|
232
|
+
void this.requestLocationPermissionCb(callbacks)
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static requestLocationPermissionCb = async (callbacks: IPermissionCheckCallbacks) => {
|
|
238
|
+
const result = await this.requestLocationPermission()
|
|
239
|
+
void callbacks.onAllowPermissionRequest(result)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static requestLocationPermission = async () => {
|
|
243
|
+
const result = await request(LocationPermission, {
|
|
244
|
+
title: i18n.t('permission:location_permission_request_title_'+Platform.OS),
|
|
245
|
+
message: i18n.t('permission:location_permission_request_message_'+Platform.OS),
|
|
246
|
+
buttonPositive: i18n.t('general:button.confirm'),
|
|
247
|
+
buttonNegative: `${i18n.t('general:button.cancel')}`,
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
logger.log(`requestPermission result ${result}`)
|
|
251
|
+
|
|
252
|
+
return result
|
|
253
|
+
}
|
|
254
|
+
*/
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export default PermissionCheck
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file defines the base application styles.
|
|
3
|
+
*
|
|
4
|
+
* Use it to define generic component styles (e.g. the default text styles, default button styles...).
|
|
5
|
+
*/
|
|
6
|
+
import { StyleSheet } from 'react-native'
|
|
7
|
+
|
|
8
|
+
import { IThemeCommonParams, StyleType, ThemeCommon } from '@/theme/types'
|
|
9
|
+
import { normalize } from '@/utils'
|
|
10
|
+
|
|
11
|
+
import buttonStyles from './components/Buttons'
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param Theme can be spread like {Colors, Gutters, Layout, Common, ...args}
|
|
15
|
+
* @return {*}
|
|
16
|
+
*/
|
|
17
|
+
export default ({
|
|
18
|
+
Colors: colors,
|
|
19
|
+
Fonts: fonts,
|
|
20
|
+
...args
|
|
21
|
+
}: IThemeCommonParams): ThemeCommon => {
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
button: buttonStyles({
|
|
25
|
+
Colors: colors,
|
|
26
|
+
Fonts: fonts,
|
|
27
|
+
...args,
|
|
28
|
+
}),
|
|
29
|
+
...StyleSheet.create({
|
|
30
|
+
backgroundPrimary: { backgroundColor: colors.primary },
|
|
31
|
+
backgroundReset: { backgroundColor: colors.transparent },
|
|
32
|
+
textInput: {
|
|
33
|
+
// borderWidth: 1,
|
|
34
|
+
// borderColor: colors.primary,
|
|
35
|
+
// backgroundColor: colors.inputBackground,
|
|
36
|
+
// borderRadius: 4,
|
|
37
|
+
// color: colors.text,
|
|
38
|
+
// minHeight: 34,
|
|
39
|
+
// textAlign: 'left',
|
|
40
|
+
// padding: 8,
|
|
41
|
+
// marginTop: 10,
|
|
42
|
+
// marginBottom: 10,
|
|
43
|
+
height: normalize(44),
|
|
44
|
+
fontSize: fonts.textInputMedium.fontSize,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
}
|
|
48
|
+
}
|