-
Notifications
You must be signed in to change notification settings - Fork 474
Convert library to TurboModule #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 36 commits
be521e4
1ede6e7
125cee4
d7a1927
466b93e
874d715
f284faf
851d817
1a5587a
1a99729
c4757c0
db4da7b
0e6a420
d82c80f
abed02f
d2c56ef
6007b94
a39a698
109011e
c6be49f
47eaff3
6d2faaa
8a47c53
11228e5
25157ea
51b91b2
f18666b
509b4bc
a1cbaeb
6f50030
2b07b10
1169935
e6ed072
16b2165
7bcb08b
31d0da2
2e93938
b84f11e
0d41f20
f4edc00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.reactnativecommunity.asyncstorage; | ||
|
||
import com.facebook.react.TurboReactPackage; | ||
import com.facebook.react.ViewManagerOnDemandReactPackage; | ||
import com.facebook.react.bridge.ModuleSpec; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.module.annotations.ReactModule; | ||
import com.facebook.react.module.annotations.ReactModuleList; | ||
import com.facebook.react.module.model.ReactModuleInfo; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
import com.facebook.react.turbomodule.core.interfaces.TurboModule; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
@ReactModuleList( | ||
nativeModules = { | ||
AsyncStorageModule.class, | ||
} | ||
) | ||
public class AsyncStoragePackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I don't actually remember why I added that. Anyway, removed it in b84f11e. |
||
|
||
@Override | ||
public List<String> getViewManagerNames(ReactApplicationContext reactContext) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable ViewManager createViewManager( | ||
ReactApplicationContext reactContext, String viewManagerName) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public NativeModule getModule(String name, @Nonnull ReactApplicationContext reactContext) { | ||
switch (name) { | ||
case AsyncStorageModule.NAME: | ||
return new AsyncStorageModule(reactContext); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
try { | ||
Class<?> reactModuleInfoProviderClass = | ||
Class.forName("com.reactnativecommunity.asyncstorage.AsyncStoragePackage$$ReactModuleInfoProvider"); | ||
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance(); | ||
} catch (ClassNotFoundException e) { | ||
// ReactModuleSpecProcessor does not run at build-time. Create this ReactModuleInfoProvider by | ||
// hand. | ||
return new ReactModuleInfoProvider() { | ||
@Override | ||
public Map<String, ReactModuleInfo> getReactModuleInfos() { | ||
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>(); | ||
|
||
Class<? extends NativeModule>[] moduleList = | ||
new Class[] { | ||
AsyncStorageModule.class, | ||
}; | ||
|
||
for (Class<? extends NativeModule> moduleClass : moduleList) { | ||
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); | ||
|
||
reactModuleInfoMap.put( | ||
reactModule.name(), | ||
new ReactModuleInfo( | ||
reactModule.name(), | ||
moduleClass.getName(), | ||
reactModule.canOverrideExistingModule(), | ||
reactModule.needsEagerInit(), | ||
reactModule.hasConstants(), | ||
reactModule.isCxxModule(), | ||
TurboModule.class.isAssignableFrom(moduleClass))); | ||
} | ||
|
||
return reactModuleInfoMap; | ||
} | ||
}; | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
throw new RuntimeException( | ||
"No ReactModuleInfoProvider for com.reactnativecommunity.asyncstorage.AsyncStoragePackage$$ReactModuleInfoProvider", e); | ||
} | ||
} | ||
|
||
// Deprecated in RN 0.47 | ||
public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("rawtypes") | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.reactnativecommunity.asyncstorage | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.ViewManagerOnDemandReactPackage | ||
import com.facebook.react.bridge.ModuleSpec | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.annotations.ReactModule | ||
import com.facebook.react.module.annotations.ReactModuleList | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import com.facebook.react.turbomodule.core.interfaces.TurboModule | ||
import com.facebook.react.uimanager.ReactShadowNode | ||
import com.facebook.react.uimanager.ViewManager | ||
import com.reactnativecommunity.asyncstorage.next.StorageModule | ||
|
||
@ReactModuleList( | ||
nativeModules = [ | ||
StorageModule::class | ||
] | ||
) | ||
class AsyncStoragePackage : TurboReactPackage(), ViewManagerOnDemandReactPackage { | ||
krizzu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
override fun getModule(name: String, context: ReactApplicationContext): NativeModule? = when (name) { | ||
StorageModule.NAME -> StorageModule(context) | ||
else -> null | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
try { | ||
val reactModuleInfoProviderClass = | ||
Class.forName("com.reactnativecommunity.asyncstorage.AsyncStoragePackage$\$ReactModuleInfoProvider") | ||
return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider | ||
} catch (e: ClassNotFoundException) { | ||
return ReactModuleInfoProvider { | ||
val reactModule: ReactModule = StorageModule::class.java.getAnnotation( | ||
ReactModule::class.java)!! | ||
|
||
mutableMapOf( | ||
StorageModule.NAME to ReactModuleInfo( | ||
reactModule.name, | ||
StorageModule::class.java.name, | ||
reactModule.canOverrideExistingModule, | ||
reactModule.needsEagerInit, | ||
reactModule.hasConstants, | ||
reactModule.isCxxModule, | ||
TurboModule::class.java.isAssignableFrom(StorageModule::class.java) | ||
) | ||
) | ||
} | ||
} catch (e: InstantiationException) { | ||
throw RuntimeException("No ReactModuleInfoProvider for AsyncStoragePackage$\$ReactModuleInfoProvider", e) | ||
} catch (e: IllegalAccessException) { | ||
throw RuntimeException("No ReactModuleInfoProvider for AsyncStoragePackage$\$ReactModuleInfoProvider", e) | ||
} | ||
} | ||
|
||
override fun getViewManagerNames(ctx: ReactApplicationContext?): MutableList<String>? = null | ||
|
||
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec>? = null | ||
|
||
override fun createViewManager( | ||
ctx: ReactApplicationContext?, | ||
viewManagerName: String? | ||
): ViewManager<*, out ReactShadowNode<*>>? = null | ||
} |
Uh oh!
There was an error while loading. Please reload this page.