shakebug-react-native 1.0.14
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/DeviceInfo/index.js.flow +177 -0
- package/DeviceInfo/index.ts +1034 -0
- package/DeviceInfo/internal/asyncHookWrappers.ts +59 -0
- package/DeviceInfo/internal/devicesWithDynamicIsland.ts +30 -0
- package/DeviceInfo/internal/devicesWithNotch.ts +374 -0
- package/DeviceInfo/internal/nativeInterface.ts +28 -0
- package/DeviceInfo/internal/privateTypes.ts +231 -0
- package/DeviceInfo/internal/supported-platform-info.ts +97 -0
- package/DeviceInfo/internal/types.ts +19 -0
- package/DeviceInfo/web/index.js +223 -0
- package/GetLocals/src/NativeRNLocalize.ts +18 -0
- package/GetLocals/src/constants.ts +269 -0
- package/GetLocals/src/index.ts +56 -0
- package/GetLocals/src/module.ts +51 -0
- package/GetLocals/src/module.web.ts +148 -0
- package/GetLocals/src/types.ts +31 -0
- package/GetLocation/LocationError.ts +20 -0
- package/GetLocation/index.ts +46 -0
- package/GetLocation/utils.ts +89 -0
- package/ImageOrVedioPicker/src/index.ts +28 -0
- package/ImageOrVedioPicker/src/platforms/NativeImagePicker.ts +10 -0
- package/ImageOrVedioPicker/src/platforms/native.ts +61 -0
- package/ImageOrVedioPicker/src/platforms/web.ts +159 -0
- package/ImageOrVedioPicker/src/types.ts +74 -0
- package/NetInfo/src/__tests__/eventListenerCallbacks.spec.ts +332 -0
- package/NetInfo/src/__tests__/fetch.spec.ts +479 -0
- package/NetInfo/src/index.ts +186 -0
- package/NetInfo/src/internal/__mocks__/nativeModule.ts +13 -0
- package/NetInfo/src/internal/defaultConfiguration.ts +17 -0
- package/NetInfo/src/internal/defaultConfiguration.web.ts +17 -0
- package/NetInfo/src/internal/internetReachability.ts +180 -0
- package/NetInfo/src/internal/nativeInterface.ts +43 -0
- package/NetInfo/src/internal/nativeInterface.web.ts +27 -0
- package/NetInfo/src/internal/nativeModule.ts +15 -0
- package/NetInfo/src/internal/nativeModule.web.ts +306 -0
- package/NetInfo/src/internal/privateTypes.ts +41 -0
- package/NetInfo/src/internal/state.ts +137 -0
- package/NetInfo/src/internal/types.ts +128 -0
- package/README.md +246 -0
- package/RecordScreen/src/index.tsx +75 -0
- package/ScreenShot/src/RNViewShot.js +3 -0
- package/ScreenShot/src/RNViewShot.web.js +42 -0
- package/ScreenShot/src/index.js +308 -0
- package/Sensor/src/index.js +14 -0
- package/Sensor/src/rnsensors.js +57 -0
- package/Sensor/src/sensors.js +97 -0
- package/VideoPlayer/PlayVideo.tsx +51 -0
- package/VideoPlayer/index.js +69 -0
- package/android/README.md +14 -0
- package/android/build/generated/source/buildConfig/debug/com/shakebug/BuildConfig.java +10 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +42 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +18 -0
- package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +6 -0
- package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +1 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/R.txt +47 -0
- package/android/build/intermediates/compiled_local_resources/debug/out/xml_imagepicker_provider_paths.xml.flat +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +12 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/BuildConfig.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/CustomMediaMetadataRetriever.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ImageMetadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ImagePickerProvider.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Metadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Options.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/RecordScreenModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/RecordScreenModule.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Shakebug.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ShakebugPackage.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Utility.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Utils.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/VideoMetadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$2.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$Formats.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$Results.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$ReusableByteArrayOutputStream.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +49 -0
- package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +82 -0
- package/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml +42 -0
- package/android/build/intermediates/navigation_json/debug/navigation.json +1 -0
- package/android/build/intermediates/packaged_res/debug/values/values.xml +25 -0
- package/android/build/intermediates/packaged_res/debug/xml/imagepicker_provider_paths.xml +4 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/BuildConfig.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/CustomMediaMetadataRetriever.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ImageMetadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ImagePickerProvider.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Metadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Options.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/RecordScreenModule$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/RecordScreenModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Shakebug.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ShakebugPackage.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Utility.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Utils.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/VideoMetadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$Formats.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$Results.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$ReusableByteArrayOutputStream.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot.class +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +48 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +97 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build.gradle +235 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/shakebug/AmazonFireDeviceConnectivityPoller.java +170 -0
- package/android/src/main/java/com/shakebug/BaseUtils.java +33 -0
- package/android/src/main/java/com/shakebug/BroadcastReceiverConnectivityReceiver.java +131 -0
- package/android/src/main/java/com/shakebug/ConnectivityReceiver.java +318 -0
- package/android/src/main/java/com/shakebug/CrashLoggerModule.java +48 -0
- package/android/src/main/java/com/shakebug/DateUtil.java +64 -0
- package/android/src/main/java/com/shakebug/DeviceType.java +18 -0
- package/android/src/main/java/com/shakebug/DeviceUtil.java +46 -0
- package/android/src/main/java/com/shakebug/DrawingView.java +90 -0
- package/android/src/main/java/com/shakebug/DrawingViewManager.java +38 -0
- package/android/src/main/java/com/shakebug/GetLocation.java +147 -0
- package/android/src/main/java/com/shakebug/ImageMetadata.java +42 -0
- package/android/src/main/java/com/shakebug/ImagePickerProvider.java +8 -0
- package/android/src/main/java/com/shakebug/Metadata.java +46 -0
- package/android/src/main/java/com/shakebug/NetInfoModule.java +79 -0
- package/android/src/main/java/com/shakebug/NetInfoUtils.java +50 -0
- package/android/src/main/java/com/shakebug/NetworkCallbackConnectivityReceiver.java +209 -0
- package/android/src/main/java/com/shakebug/Options.java +42 -0
- package/android/src/main/java/com/shakebug/RNDeviceModule.java +1036 -0
- package/android/src/main/java/com/shakebug/RNInstallReferrerClient.java +124 -0
- package/android/src/main/java/com/shakebug/RNLocalizeModule.java +79 -0
- package/android/src/main/java/com/shakebug/RNLocalizeModuleImpl.java +258 -0
- package/android/src/main/java/com/shakebug/ReactNativeGetLocationModule.java +95 -0
- package/android/src/main/java/com/shakebug/RecordScreenModule.java +202 -0
- package/android/src/main/java/com/shakebug/ScreenshotDetectorModule.java +63 -0
- package/android/src/main/java/com/shakebug/SettingsUtil.java +44 -0
- package/android/src/main/java/com/shakebug/Shakebug.java +181 -0
- package/android/src/main/java/com/shakebug/ShakebugPackage.java +75 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKImagePickerModule.java +56 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKImagePickerModuleImpl.java +230 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKScreenShotModule.java +196 -0
- package/android/src/main/java/com/shakebug/SharedPreferencesModule.java +39 -0
- package/android/src/main/java/com/shakebug/UnitConverter.java +48 -0
- package/android/src/main/java/com/shakebug/Utility.java +29 -0
- package/android/src/main/java/com/shakebug/Utils.java +593 -0
- package/android/src/main/java/com/shakebug/VideoMetadata.java +91 -0
- package/android/src/main/java/com/shakebug/VideoPlayerModule.java +199 -0
- package/android/src/main/java/com/shakebug/VideoThumbnailModule.java +215 -0
- package/android/src/main/java/com/shakebug/VideoTrimModule.java +372 -0
- package/android/src/main/java/com/shakebug/ViewShot.java +627 -0
- package/android/src/main/java/com/shakebug/adapters/VideoTrimmerAdapter.java +54 -0
- package/android/src/main/java/com/shakebug/callback/SingleCallback.java +11 -0
- package/android/src/main/java/com/shakebug/interfaces/IVideoTrimmerView.java +5 -0
- package/android/src/main/java/com/shakebug/interfaces/VideoPlayerListner.java +5 -0
- package/android/src/main/java/com/shakebug/interfaces/VideoTrimListener.java +10 -0
- package/android/src/main/java/com/shakebug/resolver/DeviceIdResolver.java +87 -0
- package/android/src/main/java/com/shakebug/resolver/DeviceTypeResolver.java +94 -0
- package/android/src/main/java/com/shakebug/thread/BackgroundExecutor.java +246 -0
- package/android/src/main/java/com/shakebug/thread/UiThreadExecutor.java +120 -0
- package/android/src/main/java/com/shakebug/types/CellularGeneration.java +60 -0
- package/android/src/main/java/com/shakebug/types/ConnectionType.java +26 -0
- package/android/src/main/java/com/shakebug/utils/StorageUtil.java +139 -0
- package/android/src/main/java/com/shakebug/utils/VideoTrimmerUtil.java +89 -0
- package/android/src/main/java/com/shakebug/widgets/RangeSeekBarView.java +534 -0
- package/android/src/main/java/com/shakebug/widgets/SpacesItemDecoration2.java +32 -0
- package/android/src/main/java/com/shakebug/widgets/VideoPlayerView.java +429 -0
- package/android/src/main/java/com/shakebug/widgets/VideoTrimmerView.java +477 -0
- package/android/src/main/java/com/shakebug/widgets/ZVideoView.java +48 -0
- package/android/src/main/res/drawable/custom_progress.xml +16 -0
- package/android/src/main/res/drawable/custom_thumb.xml +4 -0
- package/android/src/main/res/drawable/ic_close_button.xml +10 -0
- package/android/src/main/res/drawable/ic_video_pause_black.png +0 -0
- package/android/src/main/res/drawable/ic_video_play_black.png +0 -0
- package/android/src/main/res/drawable/ic_video_thumb_handle.png +0 -0
- package/android/src/main/res/drawable/icon_seek_bar.png +0 -0
- package/android/src/main/res/layout/video_player_view.xml +121 -0
- package/android/src/main/res/layout/video_thumb_item_layout.xml +16 -0
- package/android/src/main/res/layout/video_trimmer_view.xml +148 -0
- package/android/src/main/res/values/colors.xml +17 -0
- package/android/src/main/res/values/strings.xml +14 -0
- package/android/src/main/res/xml/imagepicker_provider_paths.xml +4 -0
- package/ios/CammeraPermission/RNCameraPermission.h +16 -0
- package/ios/CammeraPermission/RNCameraPermission.m +46 -0
- package/ios/DeviceInfo/DeviceUID.h +14 -0
- package/ios/DeviceInfo/DeviceUID.m +202 -0
- package/ios/DeviceInfo/EnvironmentUtil.h +41 -0
- package/ios/DeviceInfo/EnvironmentUtil.m +56 -0
- package/ios/DeviceInfo/RNDeviceInfo.h +22 -0
- package/ios/DeviceInfo/RNDeviceInfo.m +918 -0
- package/ios/GetLocals/ShakebugSDKRNLocalize.h +21 -0
- package/ios/GetLocals/ShakebugSDKRNLocalize.m +296 -0
- package/ios/GetLocation/SettingsUtil.h +16 -0
- package/ios/GetLocation/SettingsUtil.m +21 -0
- package/ios/GetLocation/ShakebugSDKLocationModule.h +17 -0
- package/ios/GetLocation/ShakebugSDKLocationModule.m +218 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerManager.h +40 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerManager.m +588 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerUtils.h +26 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerUtils.m +194 -0
- package/ios/MicrophonePermissionManager.h +14 -0
- package/ios/MicrophonePermissionManager.m +35 -0
- package/ios/NetInfo/RNCConnectionState.h +42 -0
- package/ios/NetInfo/RNCConnectionState.m +119 -0
- package/ios/NetInfo/RNCConnectionStateWatcher.h +31 -0
- package/ios/NetInfo/RNCConnectionStateWatcher.m +136 -0
- package/ios/NetInfo/RNCNetInfo.h +13 -0
- package/ios/NetInfo/RNCNetInfo.m +269 -0
- package/ios/RecordScreen/ShakebugSDKRecordScreen.h +31 -0
- package/ios/RecordScreen/ShakebugSDKRecordScreen.m +309 -0
- package/ios/ScreenShot/ShakebugSDKRNViewShot.h +6 -0
- package/ios/ScreenShot/ShakebugSDKRNViewShot.m +186 -0
- package/ios/ScreenshotDetector/ScreenShotDetector.h +12 -0
- package/ios/ScreenshotDetector/ScreenShotDetector.m +37 -0
- package/ios/Senors/RNSensorsAccelerometer.h +22 -0
- package/ios/Senors/RNSensorsAccelerometer.m +162 -0
- package/ios/Senors/RNSensorsBarometer.h +22 -0
- package/ios/Senors/RNSensorsBarometer.m +141 -0
- package/ios/Senors/RNSensorsGravity.h +22 -0
- package/ios/Senors/RNSensorsGravity.m +165 -0
- package/ios/Senors/RNSensorsGyroscope.h +22 -0
- package/ios/Senors/RNSensorsGyroscope.m +160 -0
- package/ios/Senors/RNSensorsMagnetometer.h +22 -0
- package/ios/Senors/RNSensorsMagnetometer.m +163 -0
- package/ios/Senors/RNSensorsOrientation.h +22 -0
- package/ios/Senors/RNSensorsOrientation.m +189 -0
- package/ios/Senors/RNSensorsUtils.h +7 -0
- package/ios/Senors/RNSensorsUtils.m +9 -0
- package/ios/Shakebug.h +7 -0
- package/ios/Shakebug.m +16 -0
- package/ios/Shakebug.xcodeproj/project.pbxproj +872 -0
- package/ios/Shakebug.xcodeproj/xcshareddata/xcschemes/Shakebug.xcscheme +66 -0
- package/ios/Shakebug.xcworkspace/contents.xcworkspacedata +10 -0
- package/ios/Shakebug.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/SketchCanvas/DrawingView.h +18 -0
- package/ios/SketchCanvas/DrawingView.m +96 -0
- package/ios/SketchCanvas/DrawingViewManager.h +12 -0
- package/ios/SketchCanvas/DrawingViewManager.m +35 -0
- package/ios/Storage/SharedPreferencesModule.h +13 -0
- package/ios/Storage/SharedPreferencesModule.m +35 -0
- package/ios/Thumbnaill/VideoThumbnailManager.h +12 -0
- package/ios/Thumbnaill/VideoThumbnailManager.m +73 -0
- package/ios/TrimVideo/ShakebugSDKVideoTrim.swift +372 -0
- package/ios/TrimVideo/VideoTrim-Bridging-Header.h +10 -0
- package/ios/TrimVideo/VideoTrim.m +23 -0
- package/ios/TrimVideo/VideoTrimmer.swift +810 -0
- package/ios/TrimVideo/VideoTrimmerThumb.swift +119 -0
- package/ios/TrimVideo/VideoTrimmerViewController.swift +301 -0
- package/ios/VideoPlayer/VideoPlayerModule.h +14 -0
- package/ios/VideoPlayer/VideoPlayerModule.m +29 -0
- package/ios/VideoPlayer/VideoPlayerViewController.h +18 -0
- package/ios/VideoPlayer/VideoPlayerViewController.m +29 -0
- package/package.json +45 -0
- package/shakebug-react-native.podspec +50 -0
- package/src/APIs/AddIssue.js +70 -0
- package/src/APIs/EndSession.js +32 -0
- package/src/APIs/Event.js +39 -0
- package/src/APIs/MatchKey.js +40 -0
- package/src/APIs/StartSession.js +84 -0
- package/src/Assets/images/OpenSketch.png +0 -0
- package/src/Assets/images/Push.png +0 -0
- package/src/Assets/images/RemoveTextView.png +0 -0
- package/src/Assets/images/black.png +0 -0
- package/src/Assets/images/blue.png +0 -0
- package/src/Assets/images/borderdBlack.png +0 -0
- package/src/Assets/images/borderdBlue.png +0 -0
- package/src/Assets/images/borderdGreen.png +0 -0
- package/src/Assets/images/borderdRed.png +0 -0
- package/src/Assets/images/borderdYellow.png +0 -0
- package/src/Assets/images/clear.png +0 -0
- package/src/Assets/images/close.png +0 -0
- package/src/Assets/images/green.png +0 -0
- package/src/Assets/images/next.png +0 -0
- package/src/Assets/images/play.png +0 -0
- package/src/Assets/images/red.png +0 -0
- package/src/Assets/images/shake.png +0 -0
- package/src/Assets/images/shakebugLogo.png +0 -0
- package/src/Assets/images/stopButton.png +0 -0
- package/src/Assets/images/text_icon.png +0 -0
- package/src/Assets/images/yellow.png +0 -0
- package/src/Componanats/CustomAlert.js +80 -0
- package/src/Componanats/ErrorHandler.js +80 -0
- package/src/Componanats/GlobalStateContext.js +22 -0
- package/src/Componanats/KeyboardAvoidingWrapper.js +43 -0
- package/src/Componanats/NavigationContext.js +42 -0
- package/src/Componanats/ShakeFunction.js +562 -0
- package/src/Componanats/localization.js +482 -0
- package/src/Screens/AddDetailsScreen.js +462 -0
- package/src/Screens/FirstScreen.js +629 -0
- package/src/Screens/Shakebug.js +487 -0
- package/src/Screens/StrockView.js +20 -0
- package/src/Screens/TrimVideoScreen.js +81 -0
- package/src/Screens/TutorialScreen.js +36 -0
- package/src/index.tsx +117 -0
- package/trimVideo/src/index.tsx +141 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
export const USES_FAHRENHEIT: string[] = ["BS", "BZ", "KY", "PR", "PW", "US"];
|
|
2
|
+
|
|
3
|
+
export const USES_IMPERIAL: string[] = ["LR", "MM", "US"];
|
|
4
|
+
|
|
5
|
+
export const USES_RTL_LAYOUT: string[] = [
|
|
6
|
+
"ar",
|
|
7
|
+
"ckb",
|
|
8
|
+
"fa",
|
|
9
|
+
"he",
|
|
10
|
+
"ks",
|
|
11
|
+
"lrc",
|
|
12
|
+
"mzn",
|
|
13
|
+
"ps",
|
|
14
|
+
"ug",
|
|
15
|
+
"ur",
|
|
16
|
+
"yi",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const CURRENCIES: Record<string, string> = {
|
|
20
|
+
AD: "EUR",
|
|
21
|
+
AE: "AED",
|
|
22
|
+
AF: "AFN",
|
|
23
|
+
AG: "XCD",
|
|
24
|
+
AI: "XCD",
|
|
25
|
+
AL: "ALL",
|
|
26
|
+
AM: "AMD",
|
|
27
|
+
AN: "ANG",
|
|
28
|
+
AO: "AOA",
|
|
29
|
+
AR: "ARS",
|
|
30
|
+
AS: "USD",
|
|
31
|
+
AT: "EUR",
|
|
32
|
+
AU: "AUD",
|
|
33
|
+
AW: "AWG",
|
|
34
|
+
AX: "EUR",
|
|
35
|
+
AZ: "AZN",
|
|
36
|
+
BA: "BAM",
|
|
37
|
+
BB: "BBD",
|
|
38
|
+
BD: "BDT",
|
|
39
|
+
BE: "EUR",
|
|
40
|
+
BF: "XOF",
|
|
41
|
+
BG: "BGN",
|
|
42
|
+
BH: "BHD",
|
|
43
|
+
BI: "BIF",
|
|
44
|
+
BJ: "XOF",
|
|
45
|
+
BL: "EUR",
|
|
46
|
+
BM: "BMD",
|
|
47
|
+
BN: "BND",
|
|
48
|
+
BO: "BOB",
|
|
49
|
+
BQ: "USD",
|
|
50
|
+
BR: "BRL",
|
|
51
|
+
BS: "BSD",
|
|
52
|
+
BT: "BTN",
|
|
53
|
+
BV: "NOK",
|
|
54
|
+
BW: "BWP",
|
|
55
|
+
BY: "BYN",
|
|
56
|
+
BZ: "BZD",
|
|
57
|
+
CA: "CAD",
|
|
58
|
+
CC: "AUD",
|
|
59
|
+
CD: "CDF",
|
|
60
|
+
CF: "XAF",
|
|
61
|
+
CG: "XAF",
|
|
62
|
+
CH: "CHF",
|
|
63
|
+
CI: "XOF",
|
|
64
|
+
CK: "NZD",
|
|
65
|
+
CL: "CLP",
|
|
66
|
+
CM: "XAF",
|
|
67
|
+
CN: "CNY",
|
|
68
|
+
CO: "COP",
|
|
69
|
+
CR: "CRC",
|
|
70
|
+
CU: "CUP",
|
|
71
|
+
CV: "CVE",
|
|
72
|
+
CW: "ANG",
|
|
73
|
+
CX: "AUD",
|
|
74
|
+
CY: "EUR",
|
|
75
|
+
CZ: "CZK",
|
|
76
|
+
DE: "EUR",
|
|
77
|
+
DJ: "DJF",
|
|
78
|
+
DK: "DKK",
|
|
79
|
+
DM: "XCD",
|
|
80
|
+
DO: "DOP",
|
|
81
|
+
DZ: "DZD",
|
|
82
|
+
EC: "USD",
|
|
83
|
+
EE: "EUR",
|
|
84
|
+
EG: "EGP",
|
|
85
|
+
EH: "MAD",
|
|
86
|
+
ER: "ERN",
|
|
87
|
+
ES: "EUR",
|
|
88
|
+
ET: "ETB",
|
|
89
|
+
FI: "EUR",
|
|
90
|
+
FJ: "FJD",
|
|
91
|
+
FK: "FKP",
|
|
92
|
+
FM: "USD",
|
|
93
|
+
FO: "DKK",
|
|
94
|
+
FR: "EUR",
|
|
95
|
+
GA: "XAF",
|
|
96
|
+
GB: "GBP",
|
|
97
|
+
GD: "XCD",
|
|
98
|
+
GE: "GEL",
|
|
99
|
+
GF: "EUR",
|
|
100
|
+
GG: "GBP",
|
|
101
|
+
GH: "GHS",
|
|
102
|
+
GI: "GIP",
|
|
103
|
+
GL: "DKK",
|
|
104
|
+
GM: "GMD",
|
|
105
|
+
GN: "GNF",
|
|
106
|
+
GP: "EUR",
|
|
107
|
+
GQ: "XAF",
|
|
108
|
+
GR: "EUR",
|
|
109
|
+
GS: "GBP",
|
|
110
|
+
GT: "GTQ",
|
|
111
|
+
GU: "USD",
|
|
112
|
+
GW: "XOF",
|
|
113
|
+
GY: "GYD",
|
|
114
|
+
HK: "HKD",
|
|
115
|
+
HM: "AUD",
|
|
116
|
+
HN: "HNL",
|
|
117
|
+
HR: "HRK",
|
|
118
|
+
HT: "HTG",
|
|
119
|
+
HU: "HUF",
|
|
120
|
+
ID: "IDR",
|
|
121
|
+
IE: "EUR",
|
|
122
|
+
IL: "ILS",
|
|
123
|
+
IM: "GBP",
|
|
124
|
+
IN: "INR",
|
|
125
|
+
IO: "USD",
|
|
126
|
+
IQ: "IQD",
|
|
127
|
+
IR: "IRR",
|
|
128
|
+
IS: "ISK",
|
|
129
|
+
IT: "EUR",
|
|
130
|
+
JE: "GBP",
|
|
131
|
+
JM: "JMD",
|
|
132
|
+
JO: "JOD",
|
|
133
|
+
JP: "JPY",
|
|
134
|
+
KE: "KES",
|
|
135
|
+
KG: "KGS",
|
|
136
|
+
KH: "KHR",
|
|
137
|
+
KI: "AUD",
|
|
138
|
+
KM: "KMF",
|
|
139
|
+
KN: "XCD",
|
|
140
|
+
KP: "KPW",
|
|
141
|
+
KR: "KRW",
|
|
142
|
+
KW: "KWD",
|
|
143
|
+
KY: "KYD",
|
|
144
|
+
KZ: "KZT",
|
|
145
|
+
LA: "LAK",
|
|
146
|
+
LB: "LBP",
|
|
147
|
+
LC: "XCD",
|
|
148
|
+
LI: "CHF",
|
|
149
|
+
LK: "LKR",
|
|
150
|
+
LR: "LRD",
|
|
151
|
+
LS: "LSL",
|
|
152
|
+
LT: "EUR",
|
|
153
|
+
LU: "EUR",
|
|
154
|
+
LV: "EUR",
|
|
155
|
+
LY: "LYD",
|
|
156
|
+
MA: "MAD",
|
|
157
|
+
MC: "EUR",
|
|
158
|
+
MD: "MDL",
|
|
159
|
+
ME: "EUR",
|
|
160
|
+
MF: "EUR",
|
|
161
|
+
MG: "MGA",
|
|
162
|
+
MH: "USD",
|
|
163
|
+
MK: "MKD",
|
|
164
|
+
ML: "XOF",
|
|
165
|
+
MM: "MMK",
|
|
166
|
+
MN: "MNT",
|
|
167
|
+
MO: "MOP",
|
|
168
|
+
MP: "USD",
|
|
169
|
+
MQ: "EUR",
|
|
170
|
+
MR: "MRO",
|
|
171
|
+
MS: "XCD",
|
|
172
|
+
MT: "EUR",
|
|
173
|
+
MU: "MUR",
|
|
174
|
+
MV: "MVR",
|
|
175
|
+
MW: "MWK",
|
|
176
|
+
MX: "MXN",
|
|
177
|
+
MY: "MYR",
|
|
178
|
+
MZ: "MZN",
|
|
179
|
+
NA: "NAD",
|
|
180
|
+
NC: "XPF",
|
|
181
|
+
NE: "XOF",
|
|
182
|
+
NF: "AUD",
|
|
183
|
+
NG: "NGN",
|
|
184
|
+
NI: "NIO",
|
|
185
|
+
NL: "EUR",
|
|
186
|
+
NO: "NOK",
|
|
187
|
+
NP: "NPR",
|
|
188
|
+
NR: "AUD",
|
|
189
|
+
NU: "NZD",
|
|
190
|
+
NZ: "NZD",
|
|
191
|
+
OM: "OMR",
|
|
192
|
+
PA: "PAB",
|
|
193
|
+
PE: "PEN",
|
|
194
|
+
PF: "XPF",
|
|
195
|
+
PG: "PGK",
|
|
196
|
+
PH: "PHP",
|
|
197
|
+
PK: "PKR",
|
|
198
|
+
PL: "PLN",
|
|
199
|
+
PM: "EUR",
|
|
200
|
+
PN: "NZD",
|
|
201
|
+
PR: "USD",
|
|
202
|
+
PS: "ILS",
|
|
203
|
+
PT: "EUR",
|
|
204
|
+
PW: "USD",
|
|
205
|
+
PY: "PYG",
|
|
206
|
+
QA: "QAR",
|
|
207
|
+
RE: "EUR",
|
|
208
|
+
RO: "RON",
|
|
209
|
+
RS: "RSD",
|
|
210
|
+
RU: "RUB",
|
|
211
|
+
RW: "RWF",
|
|
212
|
+
SA: "SAR",
|
|
213
|
+
SB: "SBD",
|
|
214
|
+
SC: "SCR",
|
|
215
|
+
SD: "SDG",
|
|
216
|
+
SE: "SEK",
|
|
217
|
+
SG: "SGD",
|
|
218
|
+
SH: "SHP",
|
|
219
|
+
SI: "EUR",
|
|
220
|
+
SJ: "NOK",
|
|
221
|
+
SK: "EUR",
|
|
222
|
+
SL: "SLL",
|
|
223
|
+
SM: "EUR",
|
|
224
|
+
SN: "XOF",
|
|
225
|
+
SO: "SOS",
|
|
226
|
+
SR: "SRD",
|
|
227
|
+
SS: "SSP",
|
|
228
|
+
ST: "STD",
|
|
229
|
+
SV: "SVC",
|
|
230
|
+
SX: "ANG",
|
|
231
|
+
SY: "SYP",
|
|
232
|
+
SZ: "SZL",
|
|
233
|
+
TC: "USD",
|
|
234
|
+
TD: "XAF",
|
|
235
|
+
TF: "EUR",
|
|
236
|
+
TG: "XOF",
|
|
237
|
+
TH: "THB",
|
|
238
|
+
TJ: "TJS",
|
|
239
|
+
TK: "NZD",
|
|
240
|
+
TL: "USD",
|
|
241
|
+
TM: "TMT",
|
|
242
|
+
TN: "TND",
|
|
243
|
+
TO: "TOP",
|
|
244
|
+
TR: "TRY",
|
|
245
|
+
TT: "TTD",
|
|
246
|
+
TV: "AUD",
|
|
247
|
+
TW: "TWD",
|
|
248
|
+
TZ: "TZS",
|
|
249
|
+
UA: "UAH",
|
|
250
|
+
UG: "UGX",
|
|
251
|
+
UM: "USD",
|
|
252
|
+
US: "USD",
|
|
253
|
+
UY: "UYU",
|
|
254
|
+
UZ: "UZS",
|
|
255
|
+
VA: "EUR",
|
|
256
|
+
VC: "XCD",
|
|
257
|
+
VE: "VEF",
|
|
258
|
+
VG: "USD",
|
|
259
|
+
VI: "USD",
|
|
260
|
+
VN: "VND",
|
|
261
|
+
VU: "VUV",
|
|
262
|
+
WF: "XPF",
|
|
263
|
+
WS: "WST",
|
|
264
|
+
YE: "YER",
|
|
265
|
+
YT: "EUR",
|
|
266
|
+
ZA: "ZAR",
|
|
267
|
+
ZM: "ZMW",
|
|
268
|
+
ZW: "ZWL",
|
|
269
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getLocales } from "./module";
|
|
2
|
+
|
|
3
|
+
export function findBestLanguageTag<T extends string>(
|
|
4
|
+
languageTags: ReadonlyArray<T>,
|
|
5
|
+
): { languageTag: T; isRTL: boolean } | undefined {
|
|
6
|
+
const locales = getLocales();
|
|
7
|
+
const loweredLanguageTags = languageTags.map((tag) => tag.toLowerCase());
|
|
8
|
+
|
|
9
|
+
for (let i = 0; i < locales.length; i++) {
|
|
10
|
+
const currentLocale = locales[i];
|
|
11
|
+
|
|
12
|
+
if (!currentLocale) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { languageTag, languageCode, scriptCode, countryCode, isRTL } =
|
|
17
|
+
currentLocale;
|
|
18
|
+
|
|
19
|
+
const combinaisons = [
|
|
20
|
+
languageTag,
|
|
21
|
+
!!scriptCode ? languageCode + "-" + scriptCode : null,
|
|
22
|
+
languageCode + "-" + countryCode,
|
|
23
|
+
languageCode,
|
|
24
|
+
].filter((value): value is string => !!value);
|
|
25
|
+
|
|
26
|
+
for (let j = 0; j < combinaisons.length; j++) {
|
|
27
|
+
const combinaison = combinaisons[j]?.toLowerCase();
|
|
28
|
+
|
|
29
|
+
if (!combinaison) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const tagIndex = loweredLanguageTags.indexOf(combinaison);
|
|
34
|
+
const languageTag = languageTags[tagIndex];
|
|
35
|
+
|
|
36
|
+
if (languageTag && tagIndex !== -1) {
|
|
37
|
+
return { languageTag, isRTL };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
getCalendar,
|
|
45
|
+
getCountry,
|
|
46
|
+
getCurrencies,
|
|
47
|
+
getLocales,
|
|
48
|
+
getNumberFormatSettings,
|
|
49
|
+
getTemperatureUnit,
|
|
50
|
+
getTimeZone,
|
|
51
|
+
uses24HourClock,
|
|
52
|
+
usesAutoDateAndTime,
|
|
53
|
+
usesAutoTimeZone,
|
|
54
|
+
usesMetricSystem,
|
|
55
|
+
} from "./module";
|
|
56
|
+
export * from "./types";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import NativeModule from "./NativeRNLocalize";
|
|
2
|
+
import type {
|
|
3
|
+
Calendar,
|
|
4
|
+
Locale,
|
|
5
|
+
NumberFormatSettings,
|
|
6
|
+
TemperatureUnit,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
export function getCalendar(): Calendar {
|
|
10
|
+
return NativeModule.getCalendar() as Calendar;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getCountry(): string {
|
|
14
|
+
return NativeModule.getCountry();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getCurrencies(): string[] {
|
|
18
|
+
return NativeModule.getCurrencies();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getLocales(): Locale[] {
|
|
22
|
+
return NativeModule.getLocales() as Locale[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getNumberFormatSettings(): NumberFormatSettings {
|
|
26
|
+
return NativeModule.getNumberFormatSettings() as NumberFormatSettings;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getTemperatureUnit(): TemperatureUnit {
|
|
30
|
+
return NativeModule.getTemperatureUnit() as TemperatureUnit;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getTimeZone(): string {
|
|
34
|
+
return NativeModule.getTimeZone();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function uses24HourClock(): boolean {
|
|
38
|
+
return NativeModule.uses24HourClock();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function usesMetricSystem(): boolean {
|
|
42
|
+
return NativeModule.usesMetricSystem();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function usesAutoDateAndTime(): boolean | undefined {
|
|
46
|
+
return NativeModule.usesAutoDateAndTime() ?? undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function usesAutoTimeZone(): boolean | undefined {
|
|
50
|
+
return NativeModule.usesAutoTimeZone() ?? undefined;
|
|
51
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CURRENCIES,
|
|
3
|
+
USES_FAHRENHEIT,
|
|
4
|
+
USES_IMPERIAL,
|
|
5
|
+
USES_RTL_LAYOUT,
|
|
6
|
+
} from "./constants";
|
|
7
|
+
import type {
|
|
8
|
+
Calendar,
|
|
9
|
+
Locale,
|
|
10
|
+
NumberFormatSettings,
|
|
11
|
+
TemperatureUnit,
|
|
12
|
+
} from "./types";
|
|
13
|
+
|
|
14
|
+
function ensureCountryCode(countryCode: string): string {
|
|
15
|
+
return countryCode === "419" ? "UN" : countryCode.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function splitLanguageTag(languageTag: string): {
|
|
19
|
+
languageCode: string;
|
|
20
|
+
countryCode?: string;
|
|
21
|
+
} {
|
|
22
|
+
const [languageCode = "en", countryCode] = languageTag.split("-");
|
|
23
|
+
return { languageCode, countryCode };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function convertLanguageTagToLocale(
|
|
27
|
+
languageTag: string,
|
|
28
|
+
countryCodeFallback: string,
|
|
29
|
+
): Locale {
|
|
30
|
+
let { languageCode, countryCode } = splitLanguageTag(languageTag);
|
|
31
|
+
languageCode = languageCode.toLowerCase();
|
|
32
|
+
countryCode = ensureCountryCode(countryCode || countryCodeFallback);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
languageCode,
|
|
36
|
+
countryCode,
|
|
37
|
+
languageTag: `${languageCode}-${countryCode}`,
|
|
38
|
+
isRTL: USES_RTL_LAYOUT.includes(languageCode),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getCurrentLocale(): Locale {
|
|
43
|
+
return convertLanguageTagToLocale(navigator.language, getCountry());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getCalendar(): Calendar {
|
|
47
|
+
return "gregorian";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getCountry(): string {
|
|
51
|
+
const { languages = [navigator.language] } = navigator;
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < languages.length; i++) {
|
|
54
|
+
const language = languages[i];
|
|
55
|
+
|
|
56
|
+
if (!language) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { countryCode } = splitLanguageTag(language);
|
|
61
|
+
|
|
62
|
+
if (countryCode) {
|
|
63
|
+
return ensureCountryCode(countryCode);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return "US";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getCurrencies(): string[] {
|
|
71
|
+
const { languages = [navigator.language] } = navigator;
|
|
72
|
+
const currencies: string[] = [];
|
|
73
|
+
|
|
74
|
+
languages.forEach((language) => {
|
|
75
|
+
const { countryCode } = splitLanguageTag(language);
|
|
76
|
+
|
|
77
|
+
if (countryCode) {
|
|
78
|
+
const currency = CURRENCIES[ensureCountryCode(countryCode)];
|
|
79
|
+
|
|
80
|
+
if (currency && currencies.indexOf(currency) === -1) {
|
|
81
|
+
currencies.push(currency);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (currencies.length === 0) {
|
|
87
|
+
currencies.push("USD");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return currencies;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getLocales(): Locale[] {
|
|
94
|
+
const { languages = [navigator.language] } = navigator;
|
|
95
|
+
const countryCode = getCountry();
|
|
96
|
+
const cache: string[] = [];
|
|
97
|
+
const locales: Locale[] = [];
|
|
98
|
+
|
|
99
|
+
languages.forEach((language) => {
|
|
100
|
+
const locale = convertLanguageTagToLocale(language, countryCode);
|
|
101
|
+
|
|
102
|
+
if (cache.indexOf(locale.languageTag) === -1) {
|
|
103
|
+
locales.push(locale);
|
|
104
|
+
cache.push(locale.languageTag);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return locales;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getNumberFormatSettings(): NumberFormatSettings {
|
|
112
|
+
const { languageTag } = getCurrentLocale();
|
|
113
|
+
const formatter = new Intl.NumberFormat(languageTag);
|
|
114
|
+
const separators = formatter.format(1000000.1).replace(/\d/g, "");
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
decimalSeparator: separators[separators.length - 1] || ".",
|
|
118
|
+
groupingSeparator: separators[0] || ",",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function getTemperatureUnit(): TemperatureUnit {
|
|
123
|
+
return USES_FAHRENHEIT.includes(getCountry()) ? "fahrenheit" : "celsius";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function getTimeZone(): string {
|
|
127
|
+
const { languageTag } = getCurrentLocale();
|
|
128
|
+
const formatter = new Intl.DateTimeFormat(languageTag, { hour: "numeric" });
|
|
129
|
+
return formatter.resolvedOptions().timeZone || "Etc/UTC";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function uses24HourClock(): boolean {
|
|
133
|
+
const { languageTag } = getCurrentLocale();
|
|
134
|
+
const formatter = new Intl.DateTimeFormat(languageTag, { hour: "numeric" });
|
|
135
|
+
return !formatter.format(new Date(2000, 0, 1, 20)).match(/am|pm/i);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function usesMetricSystem(): boolean {
|
|
139
|
+
return !USES_IMPERIAL.includes(getCountry());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function usesAutoDateAndTime(): boolean | undefined {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function usesAutoTimeZone(): boolean | undefined {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type TemperatureUnit = "celsius" | "fahrenheit";
|
|
2
|
+
|
|
3
|
+
// https://developer.apple.com/documentation/foundation/nscalendaridentifier?language=objc
|
|
4
|
+
export type Calendar =
|
|
5
|
+
| "gregorian"
|
|
6
|
+
| "buddhist"
|
|
7
|
+
| "coptic"
|
|
8
|
+
| "ethiopic"
|
|
9
|
+
| "ethiopic-amete-alem"
|
|
10
|
+
| "hebrew"
|
|
11
|
+
| "indian"
|
|
12
|
+
| "islamic"
|
|
13
|
+
| "islamic-umm-al-qura"
|
|
14
|
+
| "islamic-civil"
|
|
15
|
+
| "islamic-tabular"
|
|
16
|
+
| "iso8601"
|
|
17
|
+
| "japanese"
|
|
18
|
+
| "persian";
|
|
19
|
+
|
|
20
|
+
export type Locale = Readonly<{
|
|
21
|
+
languageCode: string;
|
|
22
|
+
scriptCode?: string;
|
|
23
|
+
countryCode: string;
|
|
24
|
+
languageTag: string;
|
|
25
|
+
isRTL: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export type NumberFormatSettings = Readonly<{
|
|
29
|
+
decimalSeparator: string;
|
|
30
|
+
groupingSeparator: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type LocationErrorCode =
|
|
2
|
+
| 'CANCELLED'
|
|
3
|
+
| 'UNAVAILABLE'
|
|
4
|
+
| 'TIMEOUT'
|
|
5
|
+
| 'UNAUTHORIZED';
|
|
6
|
+
|
|
7
|
+
export default class LocationError extends Error {
|
|
8
|
+
code: LocationErrorCode;
|
|
9
|
+
|
|
10
|
+
constructor(code: LocationErrorCode, message: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const isLocationError = (error: unknown): error is LocationError => {
|
|
17
|
+
return Boolean(
|
|
18
|
+
typeof error === 'object' && error && 'code' in error && 'message' in error,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {Linking, NativeModules, Platform} from 'react-native';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
GetCurrentPositionOptions,
|
|
5
|
+
Location,
|
|
6
|
+
requestAndroidPermission,
|
|
7
|
+
} from './utils';
|
|
8
|
+
import LocationError, {isLocationError} from './LocationError';
|
|
9
|
+
|
|
10
|
+
export {default as LocationError, isLocationError} from './LocationError';
|
|
11
|
+
export type {LocationErrorCode} from './LocationError';
|
|
12
|
+
export type {GetCurrentPositionOptions, Location} from './utils';
|
|
13
|
+
|
|
14
|
+
const {OS} = Platform;
|
|
15
|
+
const {ShakebugSDKReactNativeGetLocation} = NativeModules;
|
|
16
|
+
|
|
17
|
+
const DEFAULT_OPTIONS: GetCurrentPositionOptions = {
|
|
18
|
+
enableHighAccuracy: false,
|
|
19
|
+
timeout: 60000,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const GetLocation = {
|
|
23
|
+
async getCurrentPosition(
|
|
24
|
+
options: GetCurrentPositionOptions = DEFAULT_OPTIONS,
|
|
25
|
+
): Promise<Location> {
|
|
26
|
+
const opts = {...DEFAULT_OPTIONS, ...options};
|
|
27
|
+
// if (OS === 'android') {
|
|
28
|
+
// await requestAndroidPermission(opts.enableHighAccuracy, opts.rationale);
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
return ShakebugSDKReactNativeGetLocation.getCurrentPosition(opts);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (isLocationError(error)) {
|
|
35
|
+
throw new LocationError(error.code, error.message);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
openSettings() {
|
|
42
|
+
return Linking.openSettings();
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default GetLocation;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { PermissionsAndroid, Rationale } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import LocationError from './LocationError';
|
|
4
|
+
|
|
5
|
+
const { PERMISSIONS, RESULTS } = PermissionsAndroid;
|
|
6
|
+
|
|
7
|
+
export type Location = {
|
|
8
|
+
/**
|
|
9
|
+
* The latitude, in degrees
|
|
10
|
+
*/
|
|
11
|
+
latitude: number;
|
|
12
|
+
/**
|
|
13
|
+
* The longitude, in degrees
|
|
14
|
+
*/
|
|
15
|
+
longitude: number;
|
|
16
|
+
/**
|
|
17
|
+
* The altitude if available, in meters above the WGS 84 reference ellipsoid
|
|
18
|
+
*/
|
|
19
|
+
altitude: number;
|
|
20
|
+
/**
|
|
21
|
+
* The estimated horizontal accuracy of this location, radial, in meters
|
|
22
|
+
*/
|
|
23
|
+
accuracy: number;
|
|
24
|
+
/**
|
|
25
|
+
* The speed if it is available, in meters/second over ground
|
|
26
|
+
*/
|
|
27
|
+
speed: any;
|
|
28
|
+
/**
|
|
29
|
+
* The UTC time of this fix, in milliseconds since January 1, 1970.
|
|
30
|
+
*/
|
|
31
|
+
time: number;
|
|
32
|
+
/**
|
|
33
|
+
* (Android only) The bearing, in degrees
|
|
34
|
+
*/
|
|
35
|
+
bearing?: number;
|
|
36
|
+
/**
|
|
37
|
+
* (Android only) The name of the provider that generated this fix
|
|
38
|
+
*/
|
|
39
|
+
provider?: number;
|
|
40
|
+
/**
|
|
41
|
+
* (iOS only) The vertical accuracy of the location. Negative if the altitude is invalid
|
|
42
|
+
*/
|
|
43
|
+
verticalAccuracy?: number;
|
|
44
|
+
/**
|
|
45
|
+
* (iOS only) The course of the location in degrees true North. Negative if course is invalid. (0.0 - 359.9 degrees, 0 being true North)
|
|
46
|
+
*/
|
|
47
|
+
course?: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type GetCurrentPositionOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* Set `true` to use 'fine location' (GPS) our `false` to use 'course location' (Wifi, Bluetooth, 3G).
|
|
53
|
+
*
|
|
54
|
+
* Default: false
|
|
55
|
+
*/
|
|
56
|
+
enableHighAccuracy: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The max time (in milliseconds) that you want to wait to receive a location.
|
|
59
|
+
*
|
|
60
|
+
* Default: 60000 (60 seconds)
|
|
61
|
+
*/
|
|
62
|
+
timeout: number;
|
|
63
|
+
/**
|
|
64
|
+
* Android only
|
|
65
|
+
* See the [React Native docs](https://reactnative.dev/docs/permissionsandroid#request)
|
|
66
|
+
*/
|
|
67
|
+
rationale?: Rationale;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export async function requestAndroidPermission(
|
|
71
|
+
enableHighAccuracy: boolean = false,
|
|
72
|
+
rationale?: Rationale,
|
|
73
|
+
) {
|
|
74
|
+
const permission = enableHighAccuracy
|
|
75
|
+
? PERMISSIONS.ACCESS_FINE_LOCATION
|
|
76
|
+
: PERMISSIONS.ACCESS_COARSE_LOCATION
|
|
77
|
+
|
|
78
|
+
const alreadyGranted = await PermissionsAndroid.check(permission);
|
|
79
|
+
|
|
80
|
+
if (alreadyGranted) return true;
|
|
81
|
+
|
|
82
|
+
const granted = await PermissionsAndroid.request(permission, rationale);
|
|
83
|
+
|
|
84
|
+
if (granted !== RESULTS.GRANTED) {
|
|
85
|
+
throw new LocationError('UNAUTHORIZED', 'Authorization denied');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|