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,28 @@
|
|
|
1
|
+
import {Platform} from 'react-native';
|
|
2
|
+
|
|
3
|
+
import {CameraOptions, ImageLibraryOptions, Callback} from './types';
|
|
4
|
+
import {
|
|
5
|
+
imageLibrary as nativeImageLibrary,
|
|
6
|
+
camera as nativeCamera,
|
|
7
|
+
} from './platforms/native';
|
|
8
|
+
import {
|
|
9
|
+
imageLibrary as webImageLibrary,
|
|
10
|
+
camera as webCamera,
|
|
11
|
+
} from './platforms/web';
|
|
12
|
+
|
|
13
|
+
export * from './types';
|
|
14
|
+
|
|
15
|
+
export function launchCamera(options: CameraOptions, callback?: Callback) {
|
|
16
|
+
return Platform.OS === 'web'
|
|
17
|
+
? webCamera(options, callback)
|
|
18
|
+
: nativeCamera(options, callback);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function launchImageLibrary(
|
|
22
|
+
options: ImageLibraryOptions,
|
|
23
|
+
callback?: Callback,
|
|
24
|
+
) {
|
|
25
|
+
return Platform.OS === 'web'
|
|
26
|
+
? webImageLibrary(options, callback)
|
|
27
|
+
: nativeImageLibrary(options, callback);
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
launchCamera(options: Object, callback: () => void): void;
|
|
6
|
+
launchImageLibrary(options: Object, callback: () => void): void;
|
|
7
|
+
}
|
|
8
|
+
export default TurboModuleRegistry.get<Spec>(
|
|
9
|
+
'ShakebugSDKImagePicker'
|
|
10
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CameraOptions,
|
|
5
|
+
ImageLibraryOptions,
|
|
6
|
+
Callback,
|
|
7
|
+
ImagePickerResponse,
|
|
8
|
+
} from 'react-native-library-testing/ImageOrVedioPicker/src/types';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_OPTIONS: ImageLibraryOptions & CameraOptions = {
|
|
11
|
+
mediaType: 'photo',
|
|
12
|
+
videoQuality: 'high',
|
|
13
|
+
quality: 1,
|
|
14
|
+
maxWidth: 0,
|
|
15
|
+
maxHeight: 0,
|
|
16
|
+
includeBase64: false,
|
|
17
|
+
cameraType: 'back',
|
|
18
|
+
selectionLimit: 1,
|
|
19
|
+
saveToPhotos: false,
|
|
20
|
+
durationLimit: 0,
|
|
21
|
+
includeExtra: false,
|
|
22
|
+
presentationStyle: 'pageSheet',
|
|
23
|
+
assetRepresentationMode: 'auto',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// @ts-ignore We want to check whether __turboModuleProxy exitst, it may not
|
|
27
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
28
|
+
|
|
29
|
+
const nativeImagePicker = isTurboModuleEnabled ?
|
|
30
|
+
require("./NativeImagePicker").default :
|
|
31
|
+
NativeModules.ShakebugSDKImagePicker;
|
|
32
|
+
|
|
33
|
+
export function camera(
|
|
34
|
+
options: CameraOptions,
|
|
35
|
+
callback?: Callback,
|
|
36
|
+
): Promise<ImagePickerResponse> {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
nativeImagePicker.launchCamera(
|
|
39
|
+
{...DEFAULT_OPTIONS, ...options},
|
|
40
|
+
(result: ImagePickerResponse) => {
|
|
41
|
+
if (callback) callback(result);
|
|
42
|
+
resolve(result);
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function imageLibrary(
|
|
49
|
+
options: ImageLibraryOptions,
|
|
50
|
+
callback?: Callback,
|
|
51
|
+
): Promise<ImagePickerResponse> {
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
nativeImagePicker.launchImageLibrary(
|
|
54
|
+
{...DEFAULT_OPTIONS, ...options},
|
|
55
|
+
(result: ImagePickerResponse) => {
|
|
56
|
+
if (callback) callback(result);
|
|
57
|
+
resolve(result);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CameraOptions,
|
|
3
|
+
ImageLibraryOptions,
|
|
4
|
+
Callback,
|
|
5
|
+
ImagePickerResponse,
|
|
6
|
+
ErrorCode,
|
|
7
|
+
Asset,
|
|
8
|
+
MediaType,
|
|
9
|
+
} from 'react-native-library-testing/ImageOrVedioPicker/src/types';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_OPTIONS: Pick<
|
|
12
|
+
ImageLibraryOptions & CameraOptions,
|
|
13
|
+
'mediaType' | 'includeBase64' | 'selectionLimit'
|
|
14
|
+
> = {
|
|
15
|
+
mediaType: 'photo',
|
|
16
|
+
includeBase64: false,
|
|
17
|
+
selectionLimit: 1,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function camera(
|
|
21
|
+
options: ImageLibraryOptions = DEFAULT_OPTIONS,
|
|
22
|
+
callback?: Callback,
|
|
23
|
+
): Promise<ImagePickerResponse> {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const result = {
|
|
26
|
+
errorCode: 'camera_unavailable' as ErrorCode,
|
|
27
|
+
errorMessage: 'launchCamera is not supported for web yet',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (callback) callback(result);
|
|
31
|
+
|
|
32
|
+
resolve(result);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function imageLibrary(
|
|
37
|
+
options: ImageLibraryOptions = DEFAULT_OPTIONS,
|
|
38
|
+
callback?: Callback,
|
|
39
|
+
): Promise<ImagePickerResponse> {
|
|
40
|
+
// Only supporting 'photo' mediaType for now.
|
|
41
|
+
if (options.mediaType !== 'photo') {
|
|
42
|
+
const result = {
|
|
43
|
+
errorCode: 'others' as ErrorCode,
|
|
44
|
+
errorMessage: 'For now, only photo mediaType is supported for web',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (callback) callback(result);
|
|
48
|
+
|
|
49
|
+
return Promise.resolve(result);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const input = document.createElement('input');
|
|
53
|
+
input.style.display = 'none';
|
|
54
|
+
input.setAttribute('type', 'file');
|
|
55
|
+
input.setAttribute('accept', getWebMediaType(options.mediaType));
|
|
56
|
+
|
|
57
|
+
if (options.selectionLimit! > 1) {
|
|
58
|
+
input.setAttribute('multiple', 'multiple');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.body.appendChild(input);
|
|
62
|
+
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
input.addEventListener('change', async () => {
|
|
65
|
+
if (input.files) {
|
|
66
|
+
if (options.selectionLimit! <= 1) {
|
|
67
|
+
const img = await readFile(input.files[0], {
|
|
68
|
+
includeBase64: options.includeBase64,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const result = {assets: [img]};
|
|
72
|
+
|
|
73
|
+
if (callback) callback(result);
|
|
74
|
+
|
|
75
|
+
resolve(result);
|
|
76
|
+
} else {
|
|
77
|
+
const imgs = await Promise.all(
|
|
78
|
+
Array.from(input.files).map((file) =>
|
|
79
|
+
readFile(file, {includeBase64: options.includeBase64}),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const result = {
|
|
84
|
+
didCancel: false,
|
|
85
|
+
assets: imgs,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (callback) callback(result);
|
|
89
|
+
|
|
90
|
+
resolve(result);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
document.body.removeChild(input);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const event = new MouseEvent('click');
|
|
97
|
+
input.dispatchEvent(event);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readFile(
|
|
102
|
+
targetFile: Blob,
|
|
103
|
+
options: Partial<ImageLibraryOptions>,
|
|
104
|
+
): Promise<Asset> {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
const reader = new FileReader();
|
|
107
|
+
reader.onerror = () => {
|
|
108
|
+
reject(
|
|
109
|
+
new Error(
|
|
110
|
+
`Failed to read the selected media because the operation failed.`,
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
reader.onload = ({target}) => {
|
|
115
|
+
const uri = target?.result;
|
|
116
|
+
|
|
117
|
+
const returnRaw = () =>
|
|
118
|
+
resolve({
|
|
119
|
+
uri: uri as string,
|
|
120
|
+
width: 0,
|
|
121
|
+
height: 0,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (typeof uri === 'string') {
|
|
125
|
+
const image = new Image();
|
|
126
|
+
image.src = uri;
|
|
127
|
+
image.onload = () =>
|
|
128
|
+
resolve({
|
|
129
|
+
uri,
|
|
130
|
+
width: image.naturalWidth ?? image.width,
|
|
131
|
+
height: image.naturalHeight ?? image.height,
|
|
132
|
+
// The blob's result cannot be directly decoded as Base64 without
|
|
133
|
+
// first removing the Data-URL declaration preceding the
|
|
134
|
+
// Base64-encoded data. To retrieve only the Base64 encoded string,
|
|
135
|
+
// first remove data:*/*;base64, from the result.
|
|
136
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
|
|
137
|
+
...(options.includeBase64 && {
|
|
138
|
+
base64: uri.substr(uri.indexOf(',') + 1),
|
|
139
|
+
}),
|
|
140
|
+
});
|
|
141
|
+
image.onerror = () => returnRaw();
|
|
142
|
+
} else {
|
|
143
|
+
returnRaw();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
reader.readAsDataURL(targetFile);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getWebMediaType(mediaType: MediaType) {
|
|
152
|
+
const webMediaTypes = {
|
|
153
|
+
photo: 'image/*',
|
|
154
|
+
video: 'video/*',
|
|
155
|
+
mixed: 'image/*,video/*',
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return webMediaTypes[mediaType] ?? webMediaTypes.photo;
|
|
159
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type Callback = (response: ImagePickerResponse) => any;
|
|
2
|
+
|
|
3
|
+
export interface OptionsCommon {
|
|
4
|
+
mediaType: MediaType;
|
|
5
|
+
maxWidth?: number;
|
|
6
|
+
maxHeight?: number;
|
|
7
|
+
quality?: PhotoQuality;
|
|
8
|
+
videoQuality?: AndroidVideoOptions | iOSVideoOptions;
|
|
9
|
+
includeBase64?: boolean;
|
|
10
|
+
includeExtra?: boolean;
|
|
11
|
+
formatAsMp4?: boolean;
|
|
12
|
+
presentationStyle?:
|
|
13
|
+
| 'currentContext'
|
|
14
|
+
| 'fullScreen'
|
|
15
|
+
| 'pageSheet'
|
|
16
|
+
| 'formSheet'
|
|
17
|
+
| 'popover'
|
|
18
|
+
| 'overFullScreen'
|
|
19
|
+
| 'overCurrentContext'
|
|
20
|
+
assetRepresentationMode?:
|
|
21
|
+
| 'auto'
|
|
22
|
+
| 'current'
|
|
23
|
+
| 'compatible';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ImageLibraryOptions extends OptionsCommon {
|
|
27
|
+
selectionLimit?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CameraOptions extends OptionsCommon {
|
|
31
|
+
durationLimit?: number;
|
|
32
|
+
saveToPhotos?: boolean;
|
|
33
|
+
cameraType?: CameraType;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Asset {
|
|
37
|
+
base64?: string;
|
|
38
|
+
uri?: string;
|
|
39
|
+
width?: number;
|
|
40
|
+
height?: number;
|
|
41
|
+
originalPath?: string;
|
|
42
|
+
fileSize?: number;
|
|
43
|
+
type?: string;
|
|
44
|
+
fileName?: string;
|
|
45
|
+
duration?: number;
|
|
46
|
+
bitrate?: number;
|
|
47
|
+
timestamp?: string;
|
|
48
|
+
id?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ImagePickerResponse {
|
|
52
|
+
didCancel?: boolean;
|
|
53
|
+
errorCode?: ErrorCode;
|
|
54
|
+
errorMessage?: string;
|
|
55
|
+
assets?: Asset[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type PhotoQuality =
|
|
59
|
+
| 0
|
|
60
|
+
| 0.1
|
|
61
|
+
| 0.2
|
|
62
|
+
| 0.3
|
|
63
|
+
| 0.4
|
|
64
|
+
| 0.5
|
|
65
|
+
| 0.6
|
|
66
|
+
| 0.7
|
|
67
|
+
| 0.8
|
|
68
|
+
| 0.9
|
|
69
|
+
| 1;
|
|
70
|
+
export type CameraType = 'back' | 'front';
|
|
71
|
+
export type MediaType = 'photo' | 'video' | 'mixed';
|
|
72
|
+
export type AndroidVideoOptions = 'low' | 'high';
|
|
73
|
+
export type iOSVideoOptions = 'low' | 'medium' | 'high';
|
|
74
|
+
export type ErrorCode = 'camera_unavailable' | 'permission' | 'others';
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fetchMock from 'jest-fetch-mock';
|
|
11
|
+
import NetInfo from '../index';
|
|
12
|
+
import NativeInterface from '../internal/nativeInterface';
|
|
13
|
+
import {DEVICE_CONNECTIVITY_EVENT} from '../internal/privateTypes';
|
|
14
|
+
import {NetInfoStateType, NetInfoCellularGeneration} from '../internal/types';
|
|
15
|
+
|
|
16
|
+
// Mock modules
|
|
17
|
+
fetchMock.enableMocks();
|
|
18
|
+
jest.mock('../internal/nativeModule');
|
|
19
|
+
const mockNativeModule = jest.requireMock('../internal/nativeModule').default;
|
|
20
|
+
|
|
21
|
+
beforeAll(() => {
|
|
22
|
+
mockNativeModule.getCurrentState.mockResolvedValue({
|
|
23
|
+
type: NetInfoStateType.cellular,
|
|
24
|
+
isConnected: true,
|
|
25
|
+
isInternetReachable: true,
|
|
26
|
+
details: {
|
|
27
|
+
isConnectionExpensive: true,
|
|
28
|
+
cellularGeneration: NetInfoCellularGeneration['4g'],
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('@react-native-community/netinfo listener', () => {
|
|
34
|
+
describe('Event listener callbacks', () => {
|
|
35
|
+
it('should call the listener on listening', done => {
|
|
36
|
+
const listener = jest.fn();
|
|
37
|
+
NetInfo.addEventListener(listener);
|
|
38
|
+
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
expect(listener).toBeCalled();
|
|
41
|
+
done();
|
|
42
|
+
}, 0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should call the listener on listening with multiple listeners', done => {
|
|
46
|
+
const listener1 = jest.fn();
|
|
47
|
+
const listener2 = jest.fn();
|
|
48
|
+
NetInfo.addEventListener(listener1);
|
|
49
|
+
NetInfo.addEventListener(listener2);
|
|
50
|
+
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
expect(listener1).toBeCalled();
|
|
53
|
+
expect(listener2).toBeCalled();
|
|
54
|
+
done();
|
|
55
|
+
}, 0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should call the listener when the native event is emmitted', () => {
|
|
59
|
+
const listener = jest.fn();
|
|
60
|
+
NetInfo.addEventListener(listener);
|
|
61
|
+
|
|
62
|
+
const expectedConnectionType = 'wifi';
|
|
63
|
+
const expectedEffectiveConnectionType = 'unknown';
|
|
64
|
+
const expectedConnectionInfo = {
|
|
65
|
+
type: expectedConnectionType,
|
|
66
|
+
isConnected: true,
|
|
67
|
+
isInternetReachable: true,
|
|
68
|
+
details: {
|
|
69
|
+
isConnectionExpensive: true,
|
|
70
|
+
cellularGeneration: expectedEffectiveConnectionType,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
NativeInterface.eventEmitter.emit(
|
|
75
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
76
|
+
expectedConnectionInfo,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(listener).toBeCalledWith(expectedConnectionInfo);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should call the listener multiple times when multiple native events are emmitted', () => {
|
|
83
|
+
const listener = jest.fn();
|
|
84
|
+
NetInfo.addEventListener(listener);
|
|
85
|
+
|
|
86
|
+
const cellularInfo = {
|
|
87
|
+
type: 'cellular',
|
|
88
|
+
isConnected: true,
|
|
89
|
+
isInternetReachable: true,
|
|
90
|
+
details: {
|
|
91
|
+
isConnectionExpensive: true,
|
|
92
|
+
cellularGeneration: '3g',
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const wifiInfo = {
|
|
97
|
+
type: 'wifi',
|
|
98
|
+
isConnected: true,
|
|
99
|
+
isInternetReachable: true,
|
|
100
|
+
details: {
|
|
101
|
+
isConnectionExpensive: true,
|
|
102
|
+
cellularGeneration: 'unknown',
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
NativeInterface.eventEmitter.emit(
|
|
107
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
108
|
+
cellularInfo,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
expect(listener).toBeCalledWith(cellularInfo);
|
|
112
|
+
|
|
113
|
+
NativeInterface.eventEmitter.emit(DEVICE_CONNECTIVITY_EVENT, wifiInfo);
|
|
114
|
+
|
|
115
|
+
expect(listener).toBeCalledWith(wifiInfo);
|
|
116
|
+
|
|
117
|
+
// The additional time is from the call on listen
|
|
118
|
+
expect(listener).toBeCalledTimes(3);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should call the listener with the correct data when transitioning state from connected to unconnected', () => {
|
|
122
|
+
const listener = jest.fn();
|
|
123
|
+
NetInfo.addEventListener(listener);
|
|
124
|
+
|
|
125
|
+
const cellularInfo = {
|
|
126
|
+
type: 'cellular',
|
|
127
|
+
isConnected: true,
|
|
128
|
+
isInternetReachable: true,
|
|
129
|
+
details: {
|
|
130
|
+
isConnectionExpensive: true,
|
|
131
|
+
cellularGeneration: '4g',
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const airplaneModeInfo = {
|
|
136
|
+
type: 'none',
|
|
137
|
+
isConnected: false,
|
|
138
|
+
isInternetReachable: true,
|
|
139
|
+
details: null,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Clear the stats from the call on listen
|
|
143
|
+
listener.mockClear();
|
|
144
|
+
|
|
145
|
+
NativeInterface.eventEmitter.emit(
|
|
146
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
147
|
+
cellularInfo,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
expect(listener).toBeCalledWith(cellularInfo);
|
|
151
|
+
expect(listener).toBeCalledTimes(1);
|
|
152
|
+
|
|
153
|
+
// Clear the stats from the call on listen
|
|
154
|
+
listener.mockClear();
|
|
155
|
+
|
|
156
|
+
NativeInterface.eventEmitter.emit(
|
|
157
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
158
|
+
airplaneModeInfo,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(listener).toBeCalledWith(airplaneModeInfo);
|
|
162
|
+
expect(listener).toBeCalledTimes(1);
|
|
163
|
+
|
|
164
|
+
// Clear the stats from the call on listen
|
|
165
|
+
listener.mockClear();
|
|
166
|
+
|
|
167
|
+
NativeInterface.eventEmitter.emit(
|
|
168
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
169
|
+
cellularInfo,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(listener).toBeCalledWith(cellularInfo);
|
|
173
|
+
expect(listener).toBeCalledTimes(1);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should call all listeners when the native event is emmitted', () => {
|
|
177
|
+
const listener1 = jest.fn();
|
|
178
|
+
const listener2 = jest.fn();
|
|
179
|
+
NetInfo.addEventListener(listener1);
|
|
180
|
+
NetInfo.addEventListener(listener2);
|
|
181
|
+
|
|
182
|
+
const expectedConnectionType = 'wifi';
|
|
183
|
+
const expectedEffectiveConnectionType = 'unknown';
|
|
184
|
+
|
|
185
|
+
const expectedConnectionInfo = {
|
|
186
|
+
type: expectedConnectionType,
|
|
187
|
+
isConnected: true,
|
|
188
|
+
isInternetReachable: true,
|
|
189
|
+
details: {
|
|
190
|
+
isConnectionExpensive: true,
|
|
191
|
+
cellularGeneration: expectedEffectiveConnectionType,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
NativeInterface.eventEmitter.emit(
|
|
196
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
197
|
+
expectedConnectionInfo,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
expect(listener1).toBeCalledWith(expectedConnectionInfo);
|
|
201
|
+
expect(listener2).toBeCalledWith(expectedConnectionInfo);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should not call the listener after being removed', () => {
|
|
205
|
+
const listener = jest.fn();
|
|
206
|
+
const unsubscribe = NetInfo.addEventListener(listener);
|
|
207
|
+
unsubscribe();
|
|
208
|
+
|
|
209
|
+
// Clear the stats from the call on listen
|
|
210
|
+
listener.mockClear();
|
|
211
|
+
|
|
212
|
+
NativeInterface.eventEmitter.emit(DEVICE_CONNECTIVITY_EVENT, {
|
|
213
|
+
type: 'cellular',
|
|
214
|
+
isConnected: true,
|
|
215
|
+
isInternetReachable: true,
|
|
216
|
+
details: {
|
|
217
|
+
isConnectionExpensive: true,
|
|
218
|
+
cellularGeneration: '3g',
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(listener).not.toBeCalled();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should call the remaining listeners when one has been removed', () => {
|
|
226
|
+
const listener1 = jest.fn();
|
|
227
|
+
const listener2 = jest.fn();
|
|
228
|
+
const unsubscribe1 = NetInfo.addEventListener(listener1);
|
|
229
|
+
NetInfo.addEventListener(listener2);
|
|
230
|
+
|
|
231
|
+
unsubscribe1();
|
|
232
|
+
|
|
233
|
+
// Clear the stats from the call on listen
|
|
234
|
+
listener1.mockClear();
|
|
235
|
+
|
|
236
|
+
const expectedConnectionType = 'wifi';
|
|
237
|
+
const expectedEffectiveConnectionType = 'unknown';
|
|
238
|
+
|
|
239
|
+
const expectedConnectionInfo = {
|
|
240
|
+
type: expectedConnectionType,
|
|
241
|
+
isConnected: true,
|
|
242
|
+
isInternetReachable: true,
|
|
243
|
+
details: {
|
|
244
|
+
isConnectionExpensive: true,
|
|
245
|
+
cellularGeneration: expectedEffectiveConnectionType,
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
NativeInterface.eventEmitter.emit(
|
|
250
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
251
|
+
expectedConnectionInfo,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(listener1).not.toBeCalled();
|
|
255
|
+
expect(listener2).toBeCalledWith(expectedConnectionInfo);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('with configuration options', () => {
|
|
259
|
+
beforeAll(() => {
|
|
260
|
+
// Prevent `_checkInternetReachability` from rescheduling.
|
|
261
|
+
jest.useFakeTimers();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
beforeEach(() => {
|
|
265
|
+
fetchMock.resetMocks();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('reachabilityShouldRun', () => {
|
|
269
|
+
function dataProvider() {
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
description: 'reachabilityShouldRun returns true',
|
|
273
|
+
configuration: {
|
|
274
|
+
reachabilityShouldRun: () => true,
|
|
275
|
+
},
|
|
276
|
+
expectedConnectionInfo: {
|
|
277
|
+
type: 'wifi',
|
|
278
|
+
isConnected: true,
|
|
279
|
+
details: {
|
|
280
|
+
isConnectionExpensive: true,
|
|
281
|
+
cellularGeneration: 'unknown',
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
expectedIsInternetReachable: null,
|
|
285
|
+
expectFetchToBeCalled: true,
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
description: 'reachabilityShouldRun returns false',
|
|
289
|
+
configuration: {
|
|
290
|
+
reachabilityShouldRun: () => false,
|
|
291
|
+
},
|
|
292
|
+
expectedConnectionInfo: {
|
|
293
|
+
type: 'wifi',
|
|
294
|
+
isConnected: true,
|
|
295
|
+
details: {
|
|
296
|
+
isConnectionExpensive: true,
|
|
297
|
+
cellularGeneration: 'unknown',
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
expectedIsInternetReachable: false,
|
|
301
|
+
expectFetchToBeCalled: false,
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
dataProvider().forEach(testCase => {
|
|
307
|
+
it(testCase.description, () => {
|
|
308
|
+
NetInfo.configure(testCase.configuration);
|
|
309
|
+
|
|
310
|
+
const listener = jest.fn();
|
|
311
|
+
NetInfo.addEventListener(listener);
|
|
312
|
+
|
|
313
|
+
NativeInterface.eventEmitter.emit(
|
|
314
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
315
|
+
testCase.expectedConnectionInfo,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
expect(listener).toBeCalledWith({
|
|
319
|
+
...testCase.expectedConnectionInfo,
|
|
320
|
+
isInternetReachable: testCase.expectedIsInternetReachable,
|
|
321
|
+
});
|
|
322
|
+
expect(listener).toBeCalledTimes(1);
|
|
323
|
+
|
|
324
|
+
testCase.expectFetchToBeCalled
|
|
325
|
+
? expect(fetchMock).toHaveBeenCalled()
|
|
326
|
+
: expect(fetchMock).not.toHaveBeenCalled();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|