1
+ package com.reactnativecommunity.asyncstorage
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.ViewManagerOnDemandReactPackage
5
+ import com.facebook.react.bridge.ModuleSpec
6
+ import com.facebook.react.bridge.NativeModule
7
+ import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.module.annotations.ReactModule
9
+ import com.facebook.react.module.annotations.ReactModuleList
10
+ import com.facebook.react.module.model.ReactModuleInfo
11
+ import com.facebook.react.module.model.ReactModuleInfoProvider
12
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule
13
+ import com.facebook.react.uimanager.ReactShadowNode
14
+ import com.facebook.react.uimanager.ViewManager
15
+ import com.reactnativecommunity.asyncstorage.next.StorageModule
16
+
17
+ @ReactModuleList(
18
+ nativeModules = [
19
+ StorageModule ::class
20
+ ]
21
+ )
22
+ class AsyncStoragePackage : TurboReactPackage (), ViewManagerOnDemandReactPackage {
23
+ override fun getModule (name : String , context : ReactApplicationContext ): NativeModule ? = when (name) {
24
+ StorageModule .NAME -> StorageModule (context)
25
+ else -> null
26
+ }
27
+
28
+ override fun getReactModuleInfoProvider (): ReactModuleInfoProvider {
29
+ try {
30
+ val reactModuleInfoProviderClass =
31
+ Class .forName(" com.reactnativecommunity.asyncstorage.AsyncStoragePackage$\$ ReactModuleInfoProvider" )
32
+ return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider
33
+ } catch (e: ClassNotFoundException ) {
34
+ return ReactModuleInfoProvider {
35
+ val reactModule: ReactModule = StorageModule ::class .java.getAnnotation(
36
+ ReactModule ::class .java)!!
37
+
38
+ mutableMapOf (
39
+ StorageModule .NAME to ReactModuleInfo (
40
+ reactModule.name,
41
+ StorageModule ::class .java.name,
42
+ reactModule.canOverrideExistingModule,
43
+ reactModule.needsEagerInit,
44
+ reactModule.hasConstants,
45
+ reactModule.isCxxModule,
46
+ TurboModule ::class .java.isAssignableFrom(StorageModule ::class .java)
47
+ )
48
+ )
49
+ }
50
+ } catch (e: InstantiationException ) {
51
+ throw RuntimeException (" No ReactModuleInfoProvider for AsyncStoragePackage$\$ ReactModuleInfoProvider" , e)
52
+ } catch (e: IllegalAccessException ) {
53
+ throw RuntimeException (" No ReactModuleInfoProvider for AsyncStoragePackage$\$ ReactModuleInfoProvider" , e)
54
+ }
55
+ }
56
+
57
+ override fun getViewManagerNames (ctx : ReactApplicationContext ? ): MutableList <String >? = null
58
+
59
+ override fun getViewManagers (reactContext : ReactApplicationContext ? ): MutableList <ModuleSpec >? = null
60
+
61
+ override fun createViewManager (
62
+ ctx : ReactApplicationContext ? ,
63
+ viewManagerName : String?
64
+ ): ViewManager <* , out ReactShadowNode <* >>? = null
65
+ }
0 commit comments