-
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
Merged
tido64
merged 40 commits into
react-native-async-storage:master
from
j-piasecki:@jpiasecki/turbomodule
Jul 3, 2023
Merged
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
be521e4
Init FabricExample
j-piasecki 1ede6e7
Use next implementation in the example app
j-piasecki 125cee4
Add spec and configure codegen
j-piasecki d7a1927
Setup new arch support
j-piasecki 466b93e
iOS implementation
j-piasecki 874d715
Android implementation (for java version)
j-piasecki f284faf
Use java package when next is disabled
j-piasecki 851d817
Add kotlin package
j-piasecki 1a5587a
Update kotlin module
j-piasecki 1a99729
Compatibility with the old arch
j-piasecki c4757c0
Don't look for module with old android name
j-piasecki db4da7b
Update dependencies, remove `react-native-macos`
j-piasecki 0e6a420
Update `react-native.config.js`
j-piasecki d82c80f
Add workaround for codegened files not being included
j-piasecki abed02f
Enable new arch in the example app
j-piasecki d2c56ef
Remove FabricExample
j-piasecki 6007b94
Merge branch 'master' into @jpiasecki/turbomodule
j-piasecki a39a698
Bump gradle version
j-piasecki 109011e
Rename variable
j-piasecki c6be49f
Merge remote-tracking branch 'origin/master' into @jpiasecki/turbomodule
47eaff3
TM working on iOS
6d2faaa
Turbomodule working on macOS
8a47c53
Revert changes to codegen config
11228e5
Merge remote-tracking branch 'origin/master' into @shwanton/turbomodu…
25157ea
Don't default to new arch when building iOS/macOS
51b91b2
Revert changes to babel config
f18666b
Revert version bump
509b4bc
Update RNCAsyncStorage.podspec
j-piasecki a1cbaeb
Remove devDependencies
j-piasecki 6f50030
Revert space
j-piasecki 2b07b10
Revert `build.gradle` changes
j-piasecki 1169935
Don't add codegen directory manually
j-piasecki e6ed072
Use `install_modules_dependencies`
j-piasecki 16b2165
Remove support for RN <0.71 on Android
j-piasecki 7bcb08b
Revert module resolution
j-piasecki 31d0da2
Merge branch 'master' into @shwanton/turbomodule-ios-working
2e93938
Update `build.gradle` and workflow
j-piasecki b84f11e
Remove `ViewManagerOnDemandReactPackage`
j-piasecki 0d41f20
Mention updating in comment
j-piasecki f4edc00
Rename `paper` -> `oldarch`
j-piasecki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
android/src/javaPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* 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 { | ||
|
||
@Override | ||
protected List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) { | ||
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(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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() { | ||
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 getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec>? = null | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.