From 3743b18b95f3c9c3963b26b644e7f8a81fc71cce Mon Sep 17 00:00:00 2001 From: prajnab Date: Fri, 30 Sep 2022 13:14:30 +0530 Subject: [PATCH 1/9] Added new architecture support --- android/build.gradle | 75 +++-- ...Manager.java => RNShimmerManagerImpl.java} | 57 ++-- .../com/oblador/shimmer/RNShimmerPackage.java | 2 +- .../com/oblador/shimmer/RNShimmerManager.java | 108 ++++++ .../com/oblador/shimmer/RNShimmerManager.java | 64 ++++ ios/RNShimmer.h | 12 + ios/RNShimmer.mm | 128 ++++++++ ios/RNShimmer.xcodeproj/project.pbxproj | 309 ------------------ ios/RNShimmeringView.h | 5 + ...RNShimmeringView.m => RNShimmeringView.mm} | 9 +- ios/RNShimmeringViewManager.h | 2 +- ...ewManager.m => RNShimmeringViewManager.mm} | 28 +- package.json | 43 ++- react-native-shimmer.podspec | 50 ++- src/RNShimmer.tsx | 63 ++++ src/RNShimmerNativeComponent.tsx | 27 ++ src/index.ts | 7 + 17 files changed, 574 insertions(+), 415 deletions(-) rename android/src/main/java/com/oblador/shimmer/{RNShimmerManager.java => RNShimmerManagerImpl.java} (56%) create mode 100644 android/src/newarch/java/com/oblador/shimmer/RNShimmerManager.java create mode 100644 android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java create mode 100644 ios/RNShimmer.h create mode 100644 ios/RNShimmer.mm delete mode 100755 ios/RNShimmer.xcodeproj/project.pbxproj rename ios/{RNShimmeringView.m => RNShimmeringView.mm} (94%) rename ios/{RNShimmeringViewManager.m => RNShimmeringViewManager.mm} (87%) create mode 100644 src/RNShimmer.tsx create mode 100644 src/RNShimmerNativeComponent.tsx create mode 100644 src/index.ts diff --git a/android/build.gradle b/android/build.gradle index 2addc2a..13631b1 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,44 +1,63 @@ -def safeExtGet(prop, fallback) { - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +def isNewArchitectureEnabled() { + return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" } buildscript { - repositories { - jcenter() - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' - } + ext.safeExtGet = {prop, fallback -> + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback + } + repositories { + google() + gradlePluginPortal() + } + dependencies { + classpath("com.android.tools.build:gradle:7.1.1") + } } + apply plugin: 'com.android.library' +if (isNewArchitectureEnabled()) { + apply plugin: 'com.facebook.react' +} android { - compileSdkVersion safeExtGet('compileSdkVersion', 26) - buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3') - - defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 16) - targetSdkVersion safeExtGet('targetSdkVersion', 26) - versionCode 1 - versionName "1.0" - } + compileSdkVersion safeExtGet('compileSdkVersion', 31) - lintOptions { - abortOnError false - } + defaultConfig { + minSdkVersion safeExtGet('minSdkVersion', 21) + targetSdkVersion safeExtGet('targetSdkVersion', 31) + buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) + } + sourceSets { + main { + if (isNewArchitectureEnabled()) { + java.srcDirs += ['src/newarch'] + } else { + java.srcDirs += ['src/oldarch'] + } + } + } } repositories { - jcenter() - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../node_modules/react-native/android" - } + maven { + // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm + url "$projectDir/../node_modules/react-native/android" + } + mavenCentral() + google() } dependencies { - implementation 'com.facebook.react:react-native:+' - implementation 'com.facebook.shimmer:shimmer:0.5.0@aar' + implementation 'com.facebook.react:react-native:+' + implementation 'com.facebook.shimmer:shimmer:0.5.0@aar' } + +if (isNewArchitectureEnabled()) { + react { + jsRootDir = file("../src/") + libraryName = "shimmer" + codegenJavaPackageName = "com.oblador.shimmer" + } +} \ No newline at end of file diff --git a/android/src/main/java/com/oblador/shimmer/RNShimmerManager.java b/android/src/main/java/com/oblador/shimmer/RNShimmerManagerImpl.java similarity index 56% rename from android/src/main/java/com/oblador/shimmer/RNShimmerManager.java rename to android/src/main/java/com/oblador/shimmer/RNShimmerManagerImpl.java index 17a0c84..c5c2aa0 100755 --- a/android/src/main/java/com/oblador/shimmer/RNShimmerManager.java +++ b/android/src/main/java/com/oblador/shimmer/RNShimmerManagerImpl.java @@ -1,33 +1,22 @@ package com.oblador.shimmer; - +import androidx.annotation.Nullable; import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewGroupManager; -import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.shimmer.Shimmer; -public class RNShimmerManager extends ViewGroupManager { - - public static final String REACT_CLASS = "RNShimmeringView"; - - @Override - public String getName() { - return REACT_CLASS; - } +public class RNShimmerManagerImpl { + public static final String NAME = "RNShimmeringView"; - @Override - public RNShimmeringView createViewInstance(ThemedReactContext context) { + public static RNShimmeringView createViewInstance(ThemedReactContext context) { return new RNShimmeringView(context); } - @ReactProp(name = "animating", defaultBoolean = true) - public void setAnimating(RNShimmeringView view, boolean value) { + public static void setAnimating(RNShimmeringView view, boolean value) { view.getBuilder().setAutoStart(value); view.updateShimmer(); } - @ReactProp(name = "shimmeringOpacity", defaultFloat = 0.5f) - public void setBaseOpacity(RNShimmeringView view, float value) { + public static void setShimmeringOpacity(RNShimmeringView view, float value) { if (value > 1.0f) { value = 1.0f; } @@ -39,9 +28,8 @@ public void setBaseOpacity(RNShimmeringView view, float value) { view.updateShimmer(); } - @ReactProp(name = "animationOpacity", defaultFloat = 1.0f) - public void setHighlightOpacity(RNShimmeringView view, float value) { - if (value > 1.0f) { + public static void setAnimationOpacity(RNShimmeringView view, float value) { + if (value > 1.0f) { value = 1.0f; } if (value < 0.0f) { @@ -52,8 +40,7 @@ public void setHighlightOpacity(RNShimmeringView view, float value) { view.updateShimmer(); } - @ReactProp(name = "shimmeringDirection") - public void setDirection(RNShimmeringView view, String value) { + public static void setShimmeringDirection(RNShimmeringView view, @Nullable String value) { int direction = Shimmer.Direction.LEFT_TO_RIGHT; switch (value) { case "up": @@ -74,8 +61,7 @@ public void setDirection(RNShimmeringView view, String value) { view.updateShimmer(); } - @ReactProp(name = "duration", defaultInt = 1000) - public void setDuration(RNShimmeringView view, int value) { + public static void setDuration(RNShimmeringView view, int value) { if (value < 0) { value = 0; } @@ -84,8 +70,7 @@ public void setDuration(RNShimmeringView view, int value) { view.updateShimmer(); } - @ReactProp(name = "pauseDuration", defaultInt = 400) - public void setPauseDuration(RNShimmeringView view, int value) { + public static void setPauseDuration(RNShimmeringView view, int value) { if (value < 0) { value = 0; } @@ -94,14 +79,12 @@ public void setPauseDuration(RNShimmeringView view, int value) { view.updateShimmer(); } - @ReactProp(name = "tilt", defaultFloat = 0.0f) - public void setTilt(RNShimmeringView view, int value) { + public static void setTilt(RNShimmeringView view, float value) { view.getBuilder().setTilt(value); view.updateShimmer(); } - @ReactProp(name = "intensity", defaultFloat = 0.0f) - public void setIntensity(RNShimmeringView view, float value) { + public static void setIntensity(RNShimmeringView view, float value) { if (value > 1.0f) { value = 1.0f; } @@ -112,4 +95,16 @@ public void setIntensity(RNShimmeringView view, float value) { view.getBuilder().setIntensity(value); view.updateShimmer(); } -} + + public static void setHighlightLength(RNShimmeringView view, float value) { + // Do nothing. iOS only property + } + + public static void setBeginFadeDuration(RNShimmeringView view, float value) { + // Do nothing. iOS only property + } + + public static void setEndFadeDuration(RNShimmeringView view, float value) { + // Do nothing. iOS only property + } +} \ No newline at end of file diff --git a/android/src/main/java/com/oblador/shimmer/RNShimmerPackage.java b/android/src/main/java/com/oblador/shimmer/RNShimmerPackage.java index 3f900eb..95df3df 100755 --- a/android/src/main/java/com/oblador/shimmer/RNShimmerPackage.java +++ b/android/src/main/java/com/oblador/shimmer/RNShimmerPackage.java @@ -30,7 +30,7 @@ public List> createJSModules() { public List createViewManagers( ReactApplicationContext reactContext) { return Arrays.asList( - new RNShimmerManager() + new RNShimmerManager(reactContext) ); } } diff --git a/android/src/newarch/java/com/oblador/shimmer/RNShimmerManager.java b/android/src/newarch/java/com/oblador/shimmer/RNShimmerManager.java new file mode 100644 index 0000000..bf64e7f --- /dev/null +++ b/android/src/newarch/java/com/oblador/shimmer/RNShimmerManager.java @@ -0,0 +1,108 @@ +package com.oblador.shimmer; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.ViewGroupManager; +import com.facebook.react.uimanager.ViewManagerDelegate; +import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.viewmanagers.RNShimmeringViewManagerInterface; +import com.facebook.react.viewmanagers.RNShimmeringViewManagerDelegate; + +@ReactModule(name = RNShimmerManagerImpl.NAME) +public class RNShimmerManager extends ViewGroupManager implements RNShimmeringViewManagerInterface { + + private final ViewManagerDelegate mDelegate; + + public RNShimmerManager(ReactApplicationContext context) { + mDelegate = new RNShimmeringViewManagerDelegate<>(this); + } + + @NonNull + @Override + protected ViewManagerDelegate getDelegate() { + return mDelegate; + } + + @NonNull + @Override + public String getName() { + return RNShimmerManagerImpl.NAME; + } + + @NonNull + @Override + protected RNShimmeringView createViewInstance(@NonNull ThemedReactContext context) { + return RNShimmerManagerImpl.createViewInstance(context); + } + + @Override + @ReactProp(name = "animating", defaultBoolean = true) + public void setAnimating(RNShimmeringView view, boolean value) { + RNShimmerManagerImpl.setAnimating(view, value); + } + + @Override + @ReactProp(name = "shimmeringOpacity", defaultFloat = 0.5f) + public void setShimmeringOpacity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setShimmeringOpacity(view, value); + } + + @Override + @ReactProp(name = "animationOpacity", defaultFloat = 1.0f) + public void setAnimationOpacity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setAnimationOpacity(view, value); + } + + @Override + @ReactProp(name = "shimmeringDirection") + public void setShimmeringDirection(RNShimmeringView view, @Nullable String value) { + RNShimmerManagerImpl.setShimmeringDirection(view, value); + } + + @Override + @ReactProp(name = "duration", defaultInt = 1000) + public void setDuration(RNShimmeringView view, int value) { + RNShimmerManagerImpl.setDuration(view, value); + } + + @Override + @ReactProp(name = "pauseDuration", defaultInt = 400) + public void setPauseDuration(RNShimmeringView view, int value) { + RNShimmerManagerImpl.setPauseDuration(view, value); + } + + @Override + @ReactProp(name = "tilt", defaultFloat = 0.0f) + public void setTilt(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setTilt(view, value); + } + + @Override + @ReactProp(name = "intensity", defaultFloat = 0.0f) + public void setIntensity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setIntensity(view, value); + } + + @Override + @ReactProp(name = "highlightLength", defaultFloat = 0.0f) + public void setHighlightLength(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setHighlightLength(view, value); + } + + @Override + @ReactProp(name = "beginFadeDuration", defaultFloat = 0.0f) + public void setBeginFadeDuration(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setBeginFadeDuration(view, value); + } + + @Override + @ReactProp(name = "endFadeDuration", defaultFloat = 0.0f) + public void setEndFadeDuration(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setEndFadeDuration(view, value); + } +} \ No newline at end of file diff --git a/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java b/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java new file mode 100644 index 0000000..eb85225 --- /dev/null +++ b/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java @@ -0,0 +1,64 @@ +package com.oblador.shimmer; + +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.ViewGroupManager; +import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.bridge.ReactApplicationContext; + +public class RNShimmerManager extends ViewGroupManager { + ReactApplicationContext mCallerContext; + + public RNShimmerManager(ReactApplicationContext reactContext) { + mCallerContext = reactContext; + } + + @Override + public String getName() { + return RNShimmerManagerImpl.NAME; + } + + @Override + public RNShimmeringView createViewInstance(ThemedReactContext context) { + return RNShimmerManagerImpl.createViewInstance(context); + } + + @ReactProp(name = "animating", defaultBoolean = true) + public void setAnimating(RNShimmeringView view, boolean value) { + RNShimmerManagerImpl.setAnimating(view, value); + } + + @ReactProp(name = "shimmeringOpacity", defaultFloat = 0.5f) + public void setBaseOpacity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setShimmeringOpacity(view, value); + } + + @ReactProp(name = "animationOpacity", defaultFloat = 1.0f) + public void setHighlightOpacity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setAnimationOpacity(view, value); + } + + @ReactProp(name = "shimmeringDirection") + public void setDirection(RNShimmeringView view, String value) { + RNShimmerManagerImpl.setShimmeringDirection(view, value); + } + + @ReactProp(name = "duration", defaultInt = 1000) + public void setDuration(RNShimmeringView view, int value) { + RNShimmerManagerImpl.setDuration(view, value); + } + + @ReactProp(name = "pauseDuration", defaultInt = 400) + public void setPauseDuration(RNShimmeringView view, int value) { + RNShimmerManagerImpl.setPauseDuration(view, value); + } + + @ReactProp(name = "tilt", defaultFloat = 0.0f) + public void setTilt(RNShimmeringView view, int value) { + RNShimmerManagerImpl.setTilt(view, value); + } + + @ReactProp(name = "intensity", defaultFloat = 0.0f) + public void setIntensity(RNShimmeringView view, float value) { + RNShimmerManagerImpl.setIntensity(view, value); + } +} \ No newline at end of file diff --git a/ios/RNShimmer.h b/ios/RNShimmer.h new file mode 100644 index 0000000..eb25daa --- /dev/null +++ b/ios/RNShimmer.h @@ -0,0 +1,12 @@ +#ifdef RCT_NEW_ARCH_ENABLED +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RNShimmer : RCTViewComponentView + +@end + +NS_ASSUME_NONNULL_END +#endif \ No newline at end of file diff --git a/ios/RNShimmer.mm b/ios/RNShimmer.mm new file mode 100644 index 0000000..6710444 --- /dev/null +++ b/ios/RNShimmer.mm @@ -0,0 +1,128 @@ +#ifdef RCT_NEW_ARCH_ENABLED +#import "RNShimmer.h" +#import "RNShimmeringView.h" + +#import +#import +#import +#import +#import + +#import "RCTFabricComponentsPlugins.h" + +using namespace facebook::react; + +@interface RNShimmer () +@end + +@implementation RNShimmer { + RNShimmeringView *_view; +} + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + + _view = [[RNShimmeringView alloc] init]; + + // Set default props to start shimmering. + _view.shimmering = defaultProps->animating; + _view.shimmeringAnimationOpacity = CGFloat(defaultProps->animationOpacity); + _view.shimmeringPauseDuration = CFTimeInterval(defaultProps->pauseDuration) / 1000; + _view.shimmeringDirection = FBShimmerDirection(defaultProps->shimmeringDirection); + _view.shimmeringOpacity = CGFloat(defaultProps->shimmeringOpacity); + _view.shimmeringHighlightLength = CGFloat(defaultProps->highlightLength); + _view.shimmeringBeginFadeDuration = CFTimeInterval(defaultProps->beginFadeDuration) / 1000; + _view.shimmeringEndFadeDuration = CFTimeInterval(defaultProps->endFadeDuration) / 1000; + [_view setShimmeringDuration:defaultProps->duration/1000]; // set this at the end so that all the dependent props are already set + + // If a child component is not passed + [self setDefaultSubview]; + + self.contentView = _view; + } + + return self; +} + +- (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + if (index > 0) { + RCTLogError(@"Shimmer may only contain a single subview"); + } else { + [super mountChildComponentView:childComponentView index:index]; + + _view.contentView = [self.subviews objectAtIndex:index]; + } +} + +- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps +{ + const auto &oldViewProps = *std::static_pointer_cast(_props); + const auto &newViewProps = *std::static_pointer_cast(props); + + if (oldViewProps.animating != newViewProps.animating) { + _view.shimmering = newViewProps.animating; + } + + if (oldViewProps.animationOpacity != newViewProps.animationOpacity) { + _view.shimmeringAnimationOpacity = CGFloat(newViewProps.animationOpacity); + } + + if (oldViewProps.pauseDuration != newViewProps.pauseDuration) { + _view.shimmeringPauseDuration = CFTimeInterval(newViewProps.pauseDuration) / 1000; + } + + if (oldViewProps.shimmeringDirection != newViewProps.shimmeringDirection) { + _view.shimmeringDirection = FBShimmerDirection(newViewProps.shimmeringDirection); + } + + if (oldViewProps.shimmeringOpacity != newViewProps.shimmeringOpacity) { + _view.shimmeringOpacity = CGFloat(newViewProps.shimmeringOpacity); + } + + if (oldViewProps.highlightLength != newViewProps.highlightLength) { + _view.shimmeringHighlightLength = CGFloat(newViewProps.highlightLength); + } + + if (oldViewProps.beginFadeDuration != newViewProps.beginFadeDuration) { + _view.shimmeringBeginFadeDuration = CFTimeInterval(newViewProps.beginFadeDuration) / 1000; + } + + if (oldViewProps.endFadeDuration != newViewProps.endFadeDuration) { + _view.shimmeringEndFadeDuration = CFTimeInterval(newViewProps.endFadeDuration) / 1000; + } + + if (oldViewProps.duration != newViewProps.duration) { + [_view setShimmeringDuration:newViewProps.duration/1000]; // update this at the end + } + + [super updateProps:props oldProps:oldProps]; +} + +- (void)setDefaultSubview +{ + UIView *emptyBGView = [[UIView alloc] initWithFrame:_view.bounds]; + emptyBGView.backgroundColor = self.backgroundColor; + UIView *maskView = [[UIView alloc] initWithFrame:_view.bounds]; + maskView.backgroundColor = [UIColor whiteColor]; + maskView.alpha = 0.5; + [emptyBGView addSubview:maskView]; + [emptyBGView bringSubviewToFront:maskView]; + _view.contentView = maskView; +} + +@end + +Class RNShimmeringViewCls(void) +{ + return RNShimmer.class; +} +#endif \ No newline at end of file diff --git a/ios/RNShimmer.xcodeproj/project.pbxproj b/ios/RNShimmer.xcodeproj/project.pbxproj deleted file mode 100755 index 12c564a..0000000 --- a/ios/RNShimmer.xcodeproj/project.pbxproj +++ /dev/null @@ -1,309 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 5D7E4C771C88C67400B72F0C /* RNShimmeringViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7E4C761C88C67400B72F0C /* RNShimmeringViewManager.m */; }; - 5D7E4C7A1C88C68800B72F0C /* RNShimmeringView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7E4C791C88C68800B72F0C /* RNShimmeringView.m */; }; - 5D7E4C9A1C88D74F00B72F0C /* FBShimmeringView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7E4C941C88D74F00B72F0C /* FBShimmeringView.m */; }; - 5D7E4C9B1C88D74F00B72F0C /* FBShimmeringLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D7E4C961C88D74F00B72F0C /* FBShimmeringLayer.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 5D7E4C661C88C61600B72F0C /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = "include/$(PRODUCT_NAME)"; - dstSubfolderSpec = 16; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 5D7E4C681C88C61600B72F0C /* libRNShimmer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNShimmer.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 5D7E4C751C88C67400B72F0C /* RNShimmeringViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNShimmeringViewManager.h; sourceTree = ""; }; - 5D7E4C761C88C67400B72F0C /* RNShimmeringViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNShimmeringViewManager.m; sourceTree = ""; }; - 5D7E4C781C88C68800B72F0C /* RNShimmeringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNShimmeringView.h; sourceTree = ""; }; - 5D7E4C791C88C68800B72F0C /* RNShimmeringView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNShimmeringView.m; sourceTree = ""; }; - 5D7E4C921C88D74F00B72F0C /* FBShimmering.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBShimmering.h; sourceTree = ""; }; - 5D7E4C931C88D74F00B72F0C /* FBShimmeringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBShimmeringView.h; sourceTree = ""; }; - 5D7E4C941C88D74F00B72F0C /* FBShimmeringView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBShimmeringView.m; sourceTree = ""; }; - 5D7E4C951C88D74F00B72F0C /* FBShimmeringLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBShimmeringLayer.h; sourceTree = ""; }; - 5D7E4C961C88D74F00B72F0C /* FBShimmeringLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBShimmeringLayer.m; sourceTree = ""; }; - 5D7E4C971C88D74F00B72F0C /* FBShimmering-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FBShimmering-Prefix.pch"; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 5D7E4C651C88C61600B72F0C /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5D7E4C5F1C88C61600B72F0C = { - isa = PBXGroup; - children = ( - 5D7E4C7B1C88CB0700B72F0C /* Libraries */, - 5D7E4C741C88C65800B72F0C /* Sources */, - 5D7E4C691C88C61600B72F0C /* Products */, - ); - sourceTree = ""; - }; - 5D7E4C691C88C61600B72F0C /* Products */ = { - isa = PBXGroup; - children = ( - 5D7E4C681C88C61600B72F0C /* libRNShimmer.a */, - ); - name = Products; - sourceTree = ""; - }; - 5D7E4C741C88C65800B72F0C /* Sources */ = { - isa = PBXGroup; - children = ( - 5D7E4C751C88C67400B72F0C /* RNShimmeringViewManager.h */, - 5D7E4C761C88C67400B72F0C /* RNShimmeringViewManager.m */, - 5D7E4C781C88C68800B72F0C /* RNShimmeringView.h */, - 5D7E4C791C88C68800B72F0C /* RNShimmeringView.m */, - ); - name = Sources; - sourceTree = ""; - }; - 5D7E4C7B1C88CB0700B72F0C /* Libraries */ = { - isa = PBXGroup; - children = ( - 5D7E4C991C88D74F00B72F0C /* FBShimmering */, - ); - name = Libraries; - sourceTree = ""; - }; - 5D7E4C981C88D74F00B72F0C /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 5D7E4C971C88D74F00B72F0C /* FBShimmering-Prefix.pch */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; - 5D7E4C991C88D74F00B72F0C /* FBShimmering */ = { - isa = PBXGroup; - children = ( - 5D7E4C921C88D74F00B72F0C /* FBShimmering.h */, - 5D7E4C931C88D74F00B72F0C /* FBShimmeringView.h */, - 5D7E4C941C88D74F00B72F0C /* FBShimmeringView.m */, - 5D7E4C951C88D74F00B72F0C /* FBShimmeringLayer.h */, - 5D7E4C961C88D74F00B72F0C /* FBShimmeringLayer.m */, - 5D7E4C981C88D74F00B72F0C /* Supporting Files */, - ); - name = FBShimmering; - path = Shimmer/FBShimmering; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 5D7E4C671C88C61600B72F0C /* RNShimmer */ = { - isa = PBXNativeTarget; - buildConfigurationList = 5D7E4C711C88C61600B72F0C /* Build configuration list for PBXNativeTarget "RNShimmer" */; - buildPhases = ( - 5D7E4C641C88C61600B72F0C /* Sources */, - 5D7E4C651C88C61600B72F0C /* Frameworks */, - 5D7E4C661C88C61600B72F0C /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = RNShimmer; - productName = RNShimmer; - productReference = 5D7E4C681C88C61600B72F0C /* libRNShimmer.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 5D7E4C601C88C61600B72F0C /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0720; - ORGANIZATIONNAME = "Joel Arvidsson"; - TargetAttributes = { - 5D7E4C671C88C61600B72F0C = { - CreatedOnToolsVersion = 7.2.1; - }; - }; - }; - buildConfigurationList = 5D7E4C631C88C61600B72F0C /* Build configuration list for PBXProject "RNShimmer" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 5D7E4C5F1C88C61600B72F0C; - productRefGroup = 5D7E4C691C88C61600B72F0C /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 5D7E4C671C88C61600B72F0C /* RNShimmer */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 5D7E4C641C88C61600B72F0C /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5D7E4C771C88C67400B72F0C /* RNShimmeringViewManager.m in Sources */, - 5D7E4C9A1C88D74F00B72F0C /* FBShimmeringView.m in Sources */, - 5D7E4C9B1C88D74F00B72F0C /* FBShimmeringLayer.m in Sources */, - 5D7E4C7A1C88C68800B72F0C /* RNShimmeringView.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 5D7E4C6F1C88C61600B72F0C /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 5D7E4C701C88C61600B72F0C /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 5D7E4C721C88C61600B72F0C /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../react-native/React/**", - "$(SRCROOT)/../../node_modules/react-native/React/**", - ); - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 5D7E4C731C88C61600B72F0C /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../react-native/React/**", - "$(SRCROOT)/../../node_modules/react-native/React/**", - ); - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5D7E4C631C88C61600B72F0C /* Build configuration list for PBXProject "RNShimmer" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5D7E4C6F1C88C61600B72F0C /* Debug */, - 5D7E4C701C88C61600B72F0C /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 5D7E4C711C88C61600B72F0C /* Build configuration list for PBXNativeTarget "RNShimmer" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5D7E4C721C88C61600B72F0C /* Debug */, - 5D7E4C731C88C61600B72F0C /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5D7E4C601C88C61600B72F0C /* Project object */; -} diff --git a/ios/RNShimmeringView.h b/ios/RNShimmeringView.h index 40cbbfa..faab57a 100644 --- a/ios/RNShimmeringView.h +++ b/ios/RNShimmeringView.h @@ -10,4 +10,9 @@ @interface RNShimmeringView : FBShimmeringView +#ifdef RCT_NEW_ARCH_ENABLED +- (CFTimeInterval)getShimmeringDuration; +- (void)setShimmeringDuration:(CFTimeInterval)shimmeringDuration; +#endif + @end diff --git a/ios/RNShimmeringView.m b/ios/RNShimmeringView.mm similarity index 94% rename from ios/RNShimmeringView.m rename to ios/RNShimmeringView.mm index 04837d1..f6d2601 100755 --- a/ios/RNShimmeringView.m +++ b/ios/RNShimmeringView.mm @@ -1,5 +1,5 @@ // -// RNShimmeringView.m +// RNShimmeringView.mm // RNShimmer // // Created by Joel Arvidsson on 2016-03-03. @@ -7,14 +7,18 @@ // #import "RNShimmeringView.h" -#import #import "FBShimmeringLayer.h" +#ifndef RCT_NEW_ARCH_ENABLED +#import +#endif + @implementation RNShimmeringView { CFTimeInterval _shimmeringDuration; } +#ifndef RCT_NEW_ARCH_ENABLED - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex { RCTAssert(self.contentView == nil, @"RNShimmeringView may only contain a single subview"); @@ -32,6 +36,7 @@ - (void)removeReactSubview:(UIView *)subview { return self.contentView ? @[self.contentView] : @[]; } +#endif - (void)layoutSubviews { diff --git a/ios/RNShimmeringViewManager.h b/ios/RNShimmeringViewManager.h index b7edb4a..2dcb078 100644 --- a/ios/RNShimmeringViewManager.h +++ b/ios/RNShimmeringViewManager.h @@ -10,4 +10,4 @@ @interface RNShimmeringViewManager : RCTViewManager -@end +@end \ No newline at end of file diff --git a/ios/RNShimmeringViewManager.m b/ios/RNShimmeringViewManager.mm similarity index 87% rename from ios/RNShimmeringViewManager.m rename to ios/RNShimmeringViewManager.mm index b0e7f27..2064a38 100755 --- a/ios/RNShimmeringViewManager.m +++ b/ios/RNShimmeringViewManager.mm @@ -1,5 +1,5 @@ // -// RNShimmeringViewManager.m +// RNShimmeringViewManager.mm // RNShimmer // // Created by Joel Arvidsson on 2016-03-03. @@ -7,16 +7,21 @@ // #import "RNShimmeringViewManager.h" -#import "RNShimmeringView.h" #import "FBShimmering.h" +#ifdef RCT_NEW_ARCH_ENABLED +#import "RNShimmer.h" +#else +#import "RNShimmeringView.h" +#endif + @implementation RCTConvert(FBShimmering) RCT_ENUM_CONVERTER(FBShimmerDirection, (@{ - @"down": @(FBShimmerDirectionDown), - @"up": @(FBShimmerDirectionUp), - @"left": @(FBShimmerDirectionLeft), @"right": @(FBShimmerDirectionRight), + @"left": @(FBShimmerDirectionLeft), + @"up": @(FBShimmerDirectionUp), + @"down": @(FBShimmerDirectionDown), }), FBShimmerDirectionRight, integerValue) RCT_CUSTOM_CONVERTER(CFTimeInterval, CFTimeInterval, [self double:json] / 1000.0) @@ -25,13 +30,18 @@ @implementation RCTConvert(FBShimmering) @implementation RNShimmeringViewManager +#ifdef RCT_NEW_ARCH_ENABLED +RCT_EXPORT_MODULE() +- (RNShimmer *)view +{ + return [RNShimmer new]; +} +#else RCT_EXPORT_MODULE() - - (RNShimmeringView *)view { return [RNShimmeringView new]; } - RCT_REMAP_VIEW_PROPERTY(animating, shimmering, BOOL) RCT_EXPORT_VIEW_PROPERTY(shimmeringDirection, FBShimmerDirection) RCT_REMAP_VIEW_PROPERTY(duration, shimmeringDuration, CFTimeInterval) @@ -42,6 +52,6 @@ - (RNShimmeringView *)view RCT_REMAP_VIEW_PROPERTY(highlightLength, shimmeringHighlightLength, CGFloat) RCT_REMAP_VIEW_PROPERTY(beginFadeDuration, shimmeringBeginFadeDuration, CFTimeInterval) RCT_REMAP_VIEW_PROPERTY(endFadeDuration, shimmeringEndFadeDuration, CFTimeInterval) +#endif -@end - +@end \ No newline at end of file diff --git a/package.json b/package.json index c3ebd3c..5d5e9ed 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,20 @@ { "name": "react-native-shimmer", - "version": "0.6.0", + "version": "0.7.0", "description": "Simple shimmering effect in React Native", - "main": "index.js", - "scripts": { - "test": "eslint index.js", - "format": "prettier --write *.js" - }, + "react-native": "src/index", + "source": "src/index", + "files": [ + "src", + "android", + "ios", + "react-native-shimmer.podspec", + "!android/build", + "!ios/build", + "!**/__tests__", + "!**/__fixtures__", + "!**/__mocks__" + ], "keywords": [ "react-native", "react-component", @@ -21,19 +29,13 @@ "spinner", "animation" ], - "author": { - "name": "Joel Arvidsson", - "email": "joel@oblador.se" - }, - "homepage": "https://github.com/oblador/react-native-shimmer", + "repository": "https://github.com/oblador/react-native-shimmer", + "author": "Joel Arvidsson joel@oblador.se (https://github.com/oblador)", + "license": "MIT", "bugs": { "url": "https://github.com/oblador/react-native-shimmer/issues" }, - "repository": { - "type": "git", - "url": "git://github.com/oblador/react-native-shimmer.git" - }, - "license": "MIT", + "homepage": "https://github.com/oblador/react-native-shimmer#readme", "devDependencies": { "babel-eslint": "^10.0.1", "eslint": "^5.12.1", @@ -46,10 +48,15 @@ "prettier": "^1.16.1" }, "peerDependencies": { - "react": ">=16.0.0-alpha.12 <17.0.0", - "react-native": ">=0.45.1 <1.0.0" + "react": "*", + "react-native": "*" }, "dependencies": { "prop-types": "^15.6.0" + }, + "codegenConfig": { + "name": "RNShimmerSpecs", + "type": "components", + "jsSrcsDir": "src" } } diff --git a/react-native-shimmer.podspec b/react-native-shimmer.podspec index 4e7db41..7dea64f 100644 --- a/react-native-shimmer.podspec +++ b/react-native-shimmer.podspec @@ -1,21 +1,39 @@ -require 'json' -package = JSON.parse(File.read('package.json')) -version = package["version"] +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) + +folly_version = '2021.07.22.00' +folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' Pod::Spec.new do |s| + s.name = "react-native-shimmer" + s.version = package["version"] + s.summary = package["description"] + s.description = package["description"] + s.homepage = package["homepage"] + s.license = package["license"] + s.platforms = { :ios => "11.0" } + s.author = package["author"] + s.source = { :git => package["repository"], :tag => "#{s.version}" } - s.name = 'react-native-shimmer' - s.version = version - s.homepage = 'https://github.com/oblador/react-native-shimmer' - s.license = "MIT" - s.author = { "Joel Arvidsson" => "joel@oblador.se" } - s.summary = 'Simple shimmering effect for React Native.' - s.source = { :git => 'https://github.com/oblador/react-native-shimmer.git', :tag => "v#{s.version}" } - s.source_files = 'ios/{,Shimmer/FBShimmering/}*.{h,m}' - s.preserve_paths = "**/*.js" - s.requires_arc = true - s.platform = :ios, "9.0" + s.source_files = "ios/**/*.{h,m,mm,swift}" - s.dependency 'React', '>= 0.45.1' + s.dependency "React-Core" s.dependency 'Shimmer', '~> 1' -end + + if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then + s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" + s.pod_target_xcconfig = { + "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", + "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" + } + + s.dependency "React-RCTFabric" + s.dependency "React-Codegen" + s.dependency "RCT-Folly", folly_version + s.dependency "RCTRequired" + s.dependency "RCTTypeSafety" + s.dependency "ReactCommon/turbomodule/core" + end +end \ No newline at end of file diff --git a/src/RNShimmer.tsx b/src/RNShimmer.tsx new file mode 100644 index 0000000..4b429f4 --- /dev/null +++ b/src/RNShimmer.tsx @@ -0,0 +1,63 @@ +import PropTypes from "prop-types"; +import React, { Component } from "react"; +import { ViewProps } from "react-native"; +import requireNativeComponent from "react-native/Libraries/ReactNative/requireNativeComponent"; + +export interface ShimmerProps extends ViewProps { + animating?: boolean; + direction?: "up" | "down" | "left" | "right"; + duration?: number; + pauseDuration?: number; + animationOpacity?: number; + opacity?: number; + tilt?: number; + intensity?: number; + highlightLength?: number; + beginFadeDuration?: number; + endFadeDuration?: number; +} + +export default class Shimmer extends Component { + static propTypes = { + animating: PropTypes.bool, + direction: PropTypes.oneOf(["up", "down", "left", "right"]), + duration: PropTypes.number, + pauseDuration: PropTypes.number, + animationOpacity: PropTypes.number, + opacity: PropTypes.number, + tilt: PropTypes.number, + intensity: PropTypes.number, + highlightLength: PropTypes.number, + beginFadeDuration: PropTypes.number, + endFadeDuration: PropTypes.number, + }; + + static defaultProps = { + animating: true, + animationOpacity: 1, + duration: 1000, + opacity: 0.5, + tilt: 0, + pauseDuration: 400, + beginFadeDuration: 0, + endFadeDuration: 0, + }; + + render() { + const { direction, opacity, ...props } = this.props; + return ( + + ); + } +} + +const RNShimmeringView = requireNativeComponent("RNShimmeringView", Shimmer, { + nativeOnly: { + shimmeringDirection: true, + shimmeringOpacity: true, + }, + }); diff --git a/src/RNShimmerNativeComponent.tsx b/src/RNShimmerNativeComponent.tsx new file mode 100644 index 0000000..329b03f --- /dev/null +++ b/src/RNShimmerNativeComponent.tsx @@ -0,0 +1,27 @@ +import type { HostComponent, ViewProps } from "react-native"; +import type { + Float, + Int32, + WithDefault, +} from "react-native/Libraries/Types/CodegenTypes"; +import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent"; + +export interface NativeProps extends ViewProps { + animating?: WithDefault; + animationOpacity?: WithDefault; + duration?: WithDefault; + pauseDuration?: WithDefault; + shimmeringDirection?: WithDefault<"right" | "left" | "up" | "down", "right">; + shimmeringOpacity?: WithDefault; + + highlightLength?: WithDefault; // ios only + beginFadeDuration?: WithDefault; // ios only + endFadeDuration?: WithDefault; // ios only + + intensity?: WithDefault; // android only + tilt?: WithDefault; // android only +} + +export default codegenNativeComponent( + "RNShimmeringView" +) as HostComponent; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..4cf12ed --- /dev/null +++ b/src/index.ts @@ -0,0 +1,7 @@ +const isFabricEnabled = global.nativeFabricUIManager != null; + +const shimmer = isFabricEnabled + ? require("./RNShimmerNativeComponent").default + : require("./RNShimmer").default; + +export default shimmer; From 61f8a9aa0f6cd92f2e1e8da6d550b60fad83be10 Mon Sep 17 00:00:00 2001 From: prajnab Date: Thu, 6 Oct 2022 13:26:14 +0530 Subject: [PATCH 2/9] Fixed issue with reading props in iOS(Fabric) Fixed crash when animating switch is toggled Removed index.js --- Example/app.js | 2 +- index.js | 48 ---------------------------------- ios/RNShimmeringViewManager.mm | 3 ++- 3 files changed, 3 insertions(+), 50 deletions(-) delete mode 100755 index.js diff --git a/Example/app.js b/Example/app.js index 89c7f99..d6b9932 100644 --- a/Example/app.js +++ b/Example/app.js @@ -49,7 +49,7 @@ export default function Example(props) { Animating - + Loading... diff --git a/index.js b/index.js deleted file mode 100755 index 7b0d69b..0000000 --- a/index.js +++ /dev/null @@ -1,48 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { Component } from 'react'; -import { requireNativeComponent } from 'react-native'; - -export default class Shimmer extends Component { - static propTypes = { - animating: PropTypes.bool, - direction: PropTypes.oneOf(['up', 'down', 'left', 'right']), - duration: PropTypes.number, - pauseDuration: PropTypes.number, - animationOpacity: PropTypes.number, - opacity: PropTypes.number, - tilt: PropTypes.number, - intensity: PropTypes.number, - highlightLength: PropTypes.number, - beginFadeDuration: PropTypes.number, - endFadeDuration: PropTypes.number, - }; - - static defaultProps = { - animating: true, - animationOpacity: 1, - duration: 1000, - opacity: 0.5, - tilt: 0, - pauseDuration: 400, - beginFadeDuration: 0, - endFadeDuration: 0, - }; - - render() { - const { direction, opacity, ...props } = this.props; - return ( - - ); - } -} - -const RNShimmeringView = requireNativeComponent('RNShimmeringView', Shimmer, { - nativeOnly: { - shimmeringDirection: true, - shimmeringOpacity: true, - }, -}); diff --git a/ios/RNShimmeringViewManager.mm b/ios/RNShimmeringViewManager.mm index 2064a38..dd58d3e 100755 --- a/ios/RNShimmeringViewManager.mm +++ b/ios/RNShimmeringViewManager.mm @@ -42,6 +42,8 @@ - (RNShimmeringView *)view { return [RNShimmeringView new]; } +#endif + RCT_REMAP_VIEW_PROPERTY(animating, shimmering, BOOL) RCT_EXPORT_VIEW_PROPERTY(shimmeringDirection, FBShimmerDirection) RCT_REMAP_VIEW_PROPERTY(duration, shimmeringDuration, CFTimeInterval) @@ -52,6 +54,5 @@ - (RNShimmeringView *)view RCT_REMAP_VIEW_PROPERTY(highlightLength, shimmeringHighlightLength, CGFloat) RCT_REMAP_VIEW_PROPERTY(beginFadeDuration, shimmeringBeginFadeDuration, CFTimeInterval) RCT_REMAP_VIEW_PROPERTY(endFadeDuration, shimmeringEndFadeDuration, CFTimeInterval) -#endif @end \ No newline at end of file From 10b9f11deaffee61e4c16ae57a1df51f247ca5a1 Mon Sep 17 00:00:00 2001 From: prajnab Date: Fri, 14 Oct 2022 22:50:13 +0530 Subject: [PATCH 3/9] Fixed crash in iOS new architecture --- Example/Gemfile.lock | 1 + Example/app.js | 2 +- Example/ios/Podfile.lock | 4 ++-- ios/RNShimmer.mm | 11 +++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Example/Gemfile.lock b/Example/Gemfile.lock index 795c801..230f3dd 100644 --- a/Example/Gemfile.lock +++ b/Example/Gemfile.lock @@ -89,6 +89,7 @@ GEM PLATFORMS arm64-darwin-21 + ruby DEPENDENCIES cocoapods (~> 1.11, >= 1.11.2) diff --git a/Example/app.js b/Example/app.js index d6b9932..89c7f99 100644 --- a/Example/app.js +++ b/Example/app.js @@ -49,7 +49,7 @@ export default function Example(props) { Animating - + Loading... diff --git a/Example/ios/Podfile.lock b/Example/ios/Podfile.lock index 62cbe0e..87329e5 100644 --- a/Example/ios/Podfile.lock +++ b/Example/ios/Podfile.lock @@ -302,7 +302,7 @@ PODS: - React-jsinspector (0.70.2) - React-logger (0.70.2): - glog - - react-native-shimmer (0.6.0): + - react-native-shimmer (0.7.0): - React-Core - Shimmer (~> 1) - React-perflogger (0.70.2) @@ -565,7 +565,7 @@ SPEC CHECKSUMS: React-jsiexecutor: 53bd208e5c27939c6e6365528393445a596a9a2b React-jsinspector: 26c42646ab0bb69e29e837e23754fe7121eeaf94 React-logger: 1bfd109a0ffa4c0989bbfac0c2d8c4abe4637faa - react-native-shimmer: 1c06d2f0bc09e415e0a9691301d4515a4d2b8f3f + react-native-shimmer: 0986fc7bdd32f52af80ecd6fe72bb8dfa4a1934c React-perflogger: 6009895616a455781293950bbd63d53cfc7ffbc5 React-RCTActionSheet: 5e90aa5712af18bfc86c2c6d97d4dbe0e5451c1d React-RCTAnimation: 50c44d6501f8bfb2fe885e544501f8798b4ff3d6 diff --git a/ios/RNShimmer.mm b/ios/RNShimmer.mm index 6710444..140caef 100644 --- a/ios/RNShimmer.mm +++ b/ios/RNShimmer.mm @@ -57,9 +57,16 @@ - (void)mountChildComponentView:(UIView *)childCompone if (index > 0) { RCTLogError(@"Shimmer may only contain a single subview"); } else { - [super mountChildComponentView:childComponentView index:index]; + _view.contentView = childComponentView; + [self insertSubview:childComponentView atIndex:index]; + } +} - _view.contentView = [self.subviews objectAtIndex:index]; +- (void)unmountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + if (index == 0) { + _view.contentView = nil; + [childComponentView removeFromSuperview]; } } From 42110cee95c949907ae01e0592611064a86320be Mon Sep 17 00:00:00 2001 From: prajnab Date: Mon, 17 Oct 2022 00:05:20 +0530 Subject: [PATCH 4/9] Added index.d.ts to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5d5e9ed..17696b7 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "src", "android", "ios", + "index.d.ts", "react-native-shimmer.podspec", "!android/build", "!ios/build", From d9aef7802cce0729c7bcf89bf20303a833b5fa81 Mon Sep 17 00:00:00 2001 From: prajnab Date: Tue, 25 Oct 2022 15:23:57 +0530 Subject: [PATCH 5/9] Fixed issue with shimmeringDirection and shimmeringOpacity in old architecture and updated README --- Example/app.js | 4 ++-- README.md | 26 +++++++++++++------------- index.d.ts | 20 +++++++++++--------- src/RNShimmer.tsx | 37 ++++++++++++------------------------- 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/Example/app.js b/Example/app.js index 89c7f99..a0174e1 100644 --- a/Example/app.js +++ b/Example/app.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Image, StyleSheet, Text, View, Switch } from 'react-native'; +import {Image, StyleSheet, Text, View, Switch} from 'react-native'; import Shimmer from 'react-native-shimmer'; import logoSource from './react-logo.png'; @@ -53,7 +53,7 @@ export default function Example(props) { Loading... - + diff --git a/README.md b/README.md index 82f715c..d55ac00 100755 --- a/README.md +++ b/README.md @@ -97,19 +97,19 @@ import Shimmer from 'react-native-shimmer'; ### Properties -| Prop | Description | Default | -| ----------------------- | -------------------------------------------------------------------------------------- | ------- | -| **`animating`** | Whether or not to show shimmering effect. | `true` | -| **`direction`** | The direction of shimmering animation, valid values are `up`, `down`, `left`, `right`. | `right` | -| **`duration`** | The shimmering animation duration in milliseconds. | `1000` | -| **`pauseDuration`** | The time interval between shimmerings in milliseconds. | `400` | -| **`animationOpacity`** | The opacity of the content while it is shimmering. | `1` | -| **`opacity`** | The opacity of the content before it is shimmering. | `0.5` | -| **`highlightLength`** | The highlight length of shimmering. Range of 0–1. _iOS only_ | `1` | -| **`beginFadeDuration`** | The duration of the fade used when shimmer begins. _iOS only_ | `0` | -| **`endFadeDuration`** | The duration of the fade used when shimmer ends. _iOS only_ | `0` | -| **`tilt`** | The tilt angle of the highlight, in degrees. _Android only_ | `0` | -| **`intensity`** | The intensity of the highlight mask. Range of 0–1. _Android only_ | `0` | +| Prop | Description | Default | +| --------------------------------- | -------------------------------------------------------------------------------------- | ------- | +| **`animating`** | Whether or not to show shimmering effect. | `true` | +| **`duration`** | The shimmering animation duration in milliseconds. | `1000` | +| **`pauseDuration`** | The time interval between shimmerings in milliseconds. | `400` | +| **`animationOpacity`** | The opacity of the content while it is shimmering. | `1` | +| **`shimmeringDirection`** | The direction of shimmering animation, valid values are `up`, `down`, `left`, `right`. | `right` | +| **`shimmeringOpacity`** | The opacity of the content before it is shimmering. | `0.5` | +| **`highlightLength`** | The highlight length of shimmering. Range of 0–1. _iOS only_ | `1` | +| **`beginFadeDuration`** | The duration of the fade used when shimmer begins. _iOS only_ | `0` | +| **`endFadeDuration`** | The duration of the fade used when shimmer ends. _iOS only_ | `0` | +| **`tilt`** | The tilt angle of the highlight, in degrees. _Android only_ | `0` | +| **`intensity`** | The intensity of the highlight mask. Range of 0–1. _Android only_ | `0` | ## License diff --git a/index.d.ts b/index.d.ts index bd8e15f..765f8aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,18 +1,20 @@ -import * as React from "react"; +import React from 'react'; import { ViewProps } from "react-native"; export interface ShimmerProps extends ViewProps { animating?: boolean; - direction?: "up" | "down" | "left" | "right"; + animationOpacity?: number; duration?: number; pauseDuration?: number; - animationOpacity?: number; - opacity?: number; - tilt?: number; - intensity?: number; - highlightLength?: number; - beginFadeDuration?: number; - endFadeDuration?: number; + shimmeringDirection?: "up" | "down" | "left" | "right"; + shimmeringOpacity?: number; + + highlightLength?: number; // ios only + beginFadeDuration?: number; // ios only + endFadeDuration?: number; // ios only + + intensity?: number; // android only + tilt?: number; // android only } export default class Shimmer extends React.Component {} diff --git a/src/RNShimmer.tsx b/src/RNShimmer.tsx index 4b429f4..d89a266 100644 --- a/src/RNShimmer.tsx +++ b/src/RNShimmer.tsx @@ -1,55 +1,42 @@ import PropTypes from "prop-types"; import React, { Component } from "react"; -import { ViewProps } from "react-native"; import requireNativeComponent from "react-native/Libraries/ReactNative/requireNativeComponent"; +import { ShimmerProps } from ".."; -export interface ShimmerProps extends ViewProps { - animating?: boolean; - direction?: "up" | "down" | "left" | "right"; - duration?: number; - pauseDuration?: number; - animationOpacity?: number; - opacity?: number; - tilt?: number; - intensity?: number; - highlightLength?: number; - beginFadeDuration?: number; - endFadeDuration?: number; -} export default class Shimmer extends Component { static propTypes = { animating: PropTypes.bool, - direction: PropTypes.oneOf(["up", "down", "left", "right"]), + animationOpacity: PropTypes.number, duration: PropTypes.number, pauseDuration: PropTypes.number, - animationOpacity: PropTypes.number, - opacity: PropTypes.number, - tilt: PropTypes.number, - intensity: PropTypes.number, + shimmeringDirection: PropTypes.oneOf(["up", "down", "left", "right"]), + shimmeringOpacity: PropTypes.number, highlightLength: PropTypes.number, beginFadeDuration: PropTypes.number, endFadeDuration: PropTypes.number, + tilt: PropTypes.number, + intensity: PropTypes.number, }; static defaultProps = { animating: true, animationOpacity: 1, duration: 1000, - opacity: 0.5, - tilt: 0, pauseDuration: 400, + shimmeringOpacity: 0.5, + shimmeringDirection: "right", + highlightLength: 1, beginFadeDuration: 0, endFadeDuration: 0, + tilt: 0, + intensity: 0, }; render() { - const { direction, opacity, ...props } = this.props; return ( ); } From 51cd0e06e16c1b606a526e55f957627dcc2ce02f Mon Sep 17 00:00:00 2001 From: prajnab Date: Fri, 10 Nov 2023 01:42:12 +0530 Subject: [PATCH 6/9] Fixed issue with calculating and setting the shimmer duration on load in iOS --- ios/RNShimmer.mm | 10 ++++++++-- ios/RNShimmeringView.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ios/RNShimmer.mm b/ios/RNShimmer.mm index 140caef..f9b20df 100644 --- a/ios/RNShimmer.mm +++ b/ios/RNShimmer.mm @@ -41,7 +41,7 @@ - (instancetype)initWithFrame:(CGRect)frame _view.shimmeringHighlightLength = CGFloat(defaultProps->highlightLength); _view.shimmeringBeginFadeDuration = CFTimeInterval(defaultProps->beginFadeDuration) / 1000; _view.shimmeringEndFadeDuration = CFTimeInterval(defaultProps->endFadeDuration) / 1000; - [_view setShimmeringDuration:defaultProps->duration/1000]; // set this at the end so that all the dependent props are already set + [_view setShimmeringDuration:CFTimeInterval(defaultProps->duration)/1000]; // set this at the end so that all the dependent props are already set // If a child component is not passed [self setDefaultSubview]; @@ -52,6 +52,12 @@ - (instancetype)initWithFrame:(CGRect)frame return self; } +- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics const &)layoutMetrics oldLayoutMetrics:(facebook::react::LayoutMetrics const &)oldLayoutMetrics { + [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics]; + + [_view tryCorrectSpeedFromDuration]; +} + - (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index { if (index > 0) { @@ -108,7 +114,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & } if (oldViewProps.duration != newViewProps.duration) { - [_view setShimmeringDuration:newViewProps.duration/1000]; // update this at the end + [_view setShimmeringDuration:CFTimeInterval(newViewProps.duration)/1000]; // update this at the end } [super updateProps:props oldProps:oldProps]; diff --git a/ios/RNShimmeringView.h b/ios/RNShimmeringView.h index faab57a..ccbd3c7 100644 --- a/ios/RNShimmeringView.h +++ b/ios/RNShimmeringView.h @@ -13,6 +13,7 @@ #ifdef RCT_NEW_ARCH_ENABLED - (CFTimeInterval)getShimmeringDuration; - (void)setShimmeringDuration:(CFTimeInterval)shimmeringDuration; +- (void)tryCorrectSpeedFromDuration; #endif @end From 33d53cc1163751843fb49eb1d34f384a076a8241 Mon Sep 17 00:00:00 2001 From: prajnab Date: Fri, 10 Nov 2023 01:44:19 +0530 Subject: [PATCH 7/9] Added scripts to select architecture in iOS --- Example/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Example/package.json b/Example/package.json index aa564e8..4e96ba8 100644 --- a/Example/package.json +++ b/Example/package.json @@ -5,6 +5,8 @@ "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", + "pods": "cd ios && pod install && cd ..", + "pods:new": "cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install && cd ..", "start": "react-native start", "test": "jest", "postinstall": "DESTINATION='node_modules/react-native-shimmer' LIB_FILE=`cd .. && echo \\`pwd\\`/\\`npm pack\\`` && (rm -rf $DESTINATION || true) && mkdir $DESTINATION && tar -xvzf $LIB_FILE -C $DESTINATION --strip-components 1 && rm $LIB_FILE", From 07f251c3bed2c6083603ec79b82bcca4ae1c286d Mon Sep 17 00:00:00 2001 From: prajnab Date: Fri, 10 Nov 2023 15:34:11 +0530 Subject: [PATCH 8/9] Added logic to set default props for Android --- .../com/oblador/shimmer/RNShimmeringView.java | 17 +++++++++++++++++ .../com/oblador/shimmer/RNShimmerManager.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/oblador/shimmer/RNShimmeringView.java b/android/src/main/java/com/oblador/shimmer/RNShimmeringView.java index a1cc9b6..a951015 100755 --- a/android/src/main/java/com/oblador/shimmer/RNShimmeringView.java +++ b/android/src/main/java/com/oblador/shimmer/RNShimmeringView.java @@ -14,20 +14,24 @@ public class RNShimmeringView extends ShimmerFrameLayout { public RNShimmeringView(Context context) { super(context); + this.setDefaultProps(); } public RNShimmeringView(Context context, AttributeSet attrs) { super(context, attrs); + this.setDefaultProps(); } public RNShimmeringView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + this.setDefaultProps(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public RNShimmeringView( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + this.setDefaultProps(); } public Shimmer.Builder getBuilder() { @@ -37,4 +41,17 @@ public Shimmer.Builder getBuilder() { public void updateShimmer() { setShimmer(builder.build()); } + + public void setDefaultProps() { + getBuilder().setAutoStart(true); + getBuilder().setBaseAlpha(0.5f); + getBuilder().setHighlightAlpha(1); + getBuilder().setDirection(Shimmer.Direction.LEFT_TO_RIGHT); + getBuilder().setDuration(1000); + getBuilder().setRepeatDelay(400); + getBuilder().setTilt(0); + getBuilder().setIntensity(0); + + updateShimmer(); + } } diff --git a/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java b/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java index eb85225..41f2091 100644 --- a/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java +++ b/android/src/oldarch/java/com/oblador/shimmer/RNShimmerManager.java @@ -53,7 +53,7 @@ public void setPauseDuration(RNShimmeringView view, int value) { } @ReactProp(name = "tilt", defaultFloat = 0.0f) - public void setTilt(RNShimmeringView view, int value) { + public void setTilt(RNShimmeringView view, float value) { RNShimmerManagerImpl.setTilt(view, value); } From f13c5802432ed5a349301f3718ed2ec15d335e7b Mon Sep 17 00:00:00 2001 From: prajnab Date: Sun, 5 Mar 2023 18:46:39 +0530 Subject: [PATCH 9/9] Updated RN version of example app Updated RN version of example app --- .eslintrc | 2 +- Example/.buckconfig | 6 - Example/.eslintrc.js | 2 +- Example/.flowconfig | 66 -- Example/.gitignore | 14 +- Example/.node-version | 1 - Example/.prettierrc.js | 7 + Example/.watchmanconfig | 2 +- Example/{app.js => App.tsx} | 0 Example/Gemfile | 4 +- Example/Gemfile.lock | 39 +- Example/README.md | 79 ++ .../__tests__/{App-test.js => App.test.tsx} | 3 + Example/android/app/BUCK | 55 -- Example/android/app/build.gradle | 304 ++------ Example/android/app/build_defs.bzl | 19 - .../java/com/example/ReactNativeFlipper.java | 6 +- .../android/app/src/main/AndroidManifest.xml | 3 +- .../main/java/com/example/MainActivity.java | 36 +- .../java/com/example/MainApplication.java | 65 +- .../MainApplicationReactNativeHost.java | 116 --- .../components/MainComponentsRegistry.java | 36 - ...ApplicationTurboModuleManagerDelegate.java | 48 -- .../android/app/src/main/jni/CMakeLists.txt | 7 - .../jni/MainApplicationModuleProvider.cpp | 32 - .../main/jni/MainApplicationModuleProvider.h | 16 - ...nApplicationTurboModuleManagerDelegate.cpp | 45 -- ...ainApplicationTurboModuleManagerDelegate.h | 38 - .../src/main/jni/MainComponentsRegistry.cpp | 65 -- .../app/src/main/jni/MainComponentsRegistry.h | 32 - Example/android/app/src/main/jni/OnLoad.cpp | 11 - .../res/drawable/rn_edit_text_material.xml | 2 +- .../java/com/example/ReactNativeFlipper.java | 20 + Example/android/build.gradle | 42 +- Example/android/gradle.properties | 6 +- .../android/gradle/wrapper/gradle-wrapper.jar | Bin 59821 -> 61574 bytes .../gradle/wrapper/gradle-wrapper.properties | 3 +- Example/android/gradlew | 18 +- Example/android/gradlew.bat | 15 +- Example/android/settings.gradle | 9 +- Example/app.json | 2 +- Example/index.js | 6 +- Example/ios/Example.xcodeproj/project.pbxproj | 4 + Example/ios/Example/AppDelegate.h | 6 +- Example/ios/Example/AppDelegate.mm | 117 +-- Example/ios/Example/Info.plist | 4 +- Example/ios/Podfile | 39 +- Example/ios/Podfile.lock | 705 +++++++++++------- Example/jest.config.js | 3 + Example/metro.config.js | 20 +- Example/package.json | 33 +- Example/tsconfig.json | 3 + 52 files changed, 767 insertions(+), 1449 deletions(-) delete mode 100644 Example/.buckconfig delete mode 100644 Example/.flowconfig delete mode 100644 Example/.node-version create mode 100644 Example/.prettierrc.js rename Example/{app.js => App.tsx} (100%) create mode 100644 Example/README.md rename Example/__tests__/{App-test.js => App.test.tsx} (73%) delete mode 100644 Example/android/app/BUCK delete mode 100644 Example/android/app/build_defs.bzl delete mode 100644 Example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java delete mode 100644 Example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java delete mode 100644 Example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java delete mode 100644 Example/android/app/src/main/jni/CMakeLists.txt delete mode 100644 Example/android/app/src/main/jni/MainApplicationModuleProvider.cpp delete mode 100644 Example/android/app/src/main/jni/MainApplicationModuleProvider.h delete mode 100644 Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp delete mode 100644 Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h delete mode 100644 Example/android/app/src/main/jni/MainComponentsRegistry.cpp delete mode 100644 Example/android/app/src/main/jni/MainComponentsRegistry.h delete mode 100644 Example/android/app/src/main/jni/OnLoad.cpp create mode 100644 Example/android/app/src/release/java/com/example/ReactNativeFlipper.java create mode 100644 Example/jest.config.js create mode 100644 Example/tsconfig.json diff --git a/.eslintrc b/.eslintrc index 881b7e5..2b25bcc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,7 @@ "react/prefer-stateless-function": [0], "react/require-default-props": [0], "import/no-extraneous-dependencies": [0], - "import/no-unresolved": [2, { ignore: ['^react(-native)?$'] }], + "import/no-unresolved": [2, { "ignore": ["^react(-native)?$"] }], "import/extensions": [2, { "js": "never", "json": "always" }] } } diff --git a/Example/.buckconfig b/Example/.buckconfig deleted file mode 100644 index 934256c..0000000 --- a/Example/.buckconfig +++ /dev/null @@ -1,6 +0,0 @@ - -[android] - target = Google Inc.:Google APIs:23 - -[maven_repositories] - central = https://repo1.maven.org/maven2 diff --git a/Example/.eslintrc.js b/Example/.eslintrc.js index 40c6dcd..187894b 100644 --- a/Example/.eslintrc.js +++ b/Example/.eslintrc.js @@ -1,4 +1,4 @@ module.exports = { root: true, - extends: '@react-native-community', + extends: '@react-native', }; diff --git a/Example/.flowconfig b/Example/.flowconfig deleted file mode 100644 index 3782e44..0000000 --- a/Example/.flowconfig +++ /dev/null @@ -1,66 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore polyfills -node_modules/react-native/Libraries/polyfills/.* - -; Flow doesn't support platforms -.*/Libraries/Utilities/LoadingView.js - -.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$ - -[untyped] -.*/node_modules/@react-native-community/cli/.*/.* - -[include] - -[libs] -node_modules/react-native/interface.js -node_modules/react-native/flow/ - -[options] -emoji=true - -exact_by_default=true - -format.bracket_spacing=false - -module.file_ext=.js -module.file_ext=.json -module.file_ext=.ios.js - -munge_underscores=true - -module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' -module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState - -[lints] -sketchy-null-number=warn -sketchy-null-mixed=warn -sketchy-number=warn -untyped-type-import=warn -nonstrict-import=warn -deprecated-type=warn -unsafe-getters-setters=warn -unnecessary-invariant=warn - -[strict] -deprecated-type -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.182.0 diff --git a/Example/.gitignore b/Example/.gitignore index 2423126..0cab2ac 100644 --- a/Example/.gitignore +++ b/Example/.gitignore @@ -31,6 +31,8 @@ local.properties *.iml *.hprof .cxx/ +*.keystore +!debug.keystore # node.js # @@ -38,12 +40,6 @@ node_modules/ npm-debug.log yarn-error.log -# BUCK -buck-out/ -\.buckd/ -*.keystore -!debug.keystore - # fastlane # # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the @@ -62,3 +58,9 @@ buck-out/ # Ruby / CocoaPods /ios/Pods/ /vendor/bundle/ + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* + +# testing +/coverage diff --git a/Example/.node-version b/Example/.node-version deleted file mode 100644 index b6a7d89..0000000 --- a/Example/.node-version +++ /dev/null @@ -1 +0,0 @@ -16 diff --git a/Example/.prettierrc.js b/Example/.prettierrc.js new file mode 100644 index 0000000..2b54074 --- /dev/null +++ b/Example/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + arrowParens: 'avoid', + bracketSameLine: true, + bracketSpacing: false, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/Example/.watchmanconfig b/Example/.watchmanconfig index 9e26dfe..0967ef4 100644 --- a/Example/.watchmanconfig +++ b/Example/.watchmanconfig @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/Example/app.js b/Example/App.tsx similarity index 100% rename from Example/app.js rename to Example/App.tsx diff --git a/Example/Gemfile b/Example/Gemfile index 5efda89..1fa2c2e 100644 --- a/Example/Gemfile +++ b/Example/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version -ruby '2.7.5' +ruby ">= 2.6.10" -gem 'cocoapods', '~> 1.11', '>= 1.11.2' +gem 'cocoapods', '~> 1.12' diff --git a/Example/Gemfile.lock b/Example/Gemfile.lock index 230f3dd..5180548 100644 --- a/Example/Gemfile.lock +++ b/Example/Gemfile.lock @@ -1,30 +1,29 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.5) + CFPropertyList (3.0.6) rexml - activesupport (6.1.7) + activesupport (7.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.1) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) algoliasearch (1.27.5) httpclient (~> 2.8, >= 2.8.3) json (>= 1.5.1) atomos (0.1.3) claide (1.1.0) - cocoapods (1.11.3) + cocoapods (1.12.1) addressable (~> 2.8) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.11.3) + cocoapods-core (= 1.12.1) cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.4.0, < 2.0) + cocoapods-downloader (>= 1.6.0, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.4.0, < 2.0) + cocoapods-trunk (>= 1.6.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) @@ -32,10 +31,10 @@ GEM gh_inspector (~> 1.0) molinillo (~> 0.8.0) nap (~> 1.0) - ruby-macho (>= 1.0, < 3.0) + ruby-macho (>= 2.3.0, < 3.0) xcodeproj (>= 1.21.0, < 2.0) - cocoapods-core (1.11.3) - activesupport (>= 5.0, < 7) + cocoapods-core (1.12.1) + activesupport (>= 5.0, < 8) addressable (~> 2.8) algoliasearch (~> 1.0) concurrent-ruby (~> 1.1) @@ -54,19 +53,19 @@ GEM netrc (~> 0.11) cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) escape (0.0.4) - ethon (0.15.0) + ethon (0.16.0) ffi (>= 1.15.0) ffi (1.15.5) fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - json (2.6.2) - minitest (5.16.3) + json (2.6.3) + minitest (5.18.1) molinillo (0.8.0) nanaimo (0.3.0) nap (1.1.0) @@ -76,7 +75,7 @@ GEM ruby-macho (2.5.1) typhoeus (1.4.0) ethon (>= 0.9.0) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) xcodeproj (1.22.0) CFPropertyList (>= 2.3.3, < 4.0) @@ -85,17 +84,15 @@ GEM colored2 (~> 3.1) nanaimo (~> 0.3.0) rexml (~> 3.2.4) - zeitwerk (2.6.1) PLATFORMS - arm64-darwin-21 ruby DEPENDENCIES - cocoapods (~> 1.11, >= 1.11.2) + cocoapods (~> 1.12) RUBY VERSION ruby 2.7.5p203 BUNDLED WITH - 2.2.27 + 2.1.4 diff --git a/Example/README.md b/Example/README.md new file mode 100644 index 0000000..12470c3 --- /dev/null +++ b/Example/README.md @@ -0,0 +1,79 @@ +This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). + +# Getting Started + +>**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. + +## Step 1: Start the Metro Server + +First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. + +To start Metro, run the following command from the _root_ of your React Native project: + +```bash +# using npm +npm start + +# OR using Yarn +yarn start +``` + +## Step 2: Start your Application + +Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: + +### For Android + +```bash +# using npm +npm run android + +# OR using Yarn +yarn android +``` + +### For iOS + +```bash +# using npm +npm run ios + +# OR using Yarn +yarn ios +``` + +If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. + +This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. + +## Step 3: Modifying your App + +Now that you have successfully run the app, let's modify it. + +1. Open `App.tsx` in your text editor of choice and edit some lines. +2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! + + For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! + +## Congratulations! :tada: + +You've successfully run and modified your React Native App. :partying_face: + +### Now what? + +- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). +- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). + +# Troubleshooting + +If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. + +# Learn More + +To learn more about React Native, take a look at the following resources: + +- [React Native Website](https://reactnative.dev) - learn more about React Native. +- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. +- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. +- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. +- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. diff --git a/Example/__tests__/App-test.js b/Example/__tests__/App.test.tsx similarity index 73% rename from Example/__tests__/App-test.js rename to Example/__tests__/App.test.tsx index 1784766..3413ac1 100644 --- a/Example/__tests__/App-test.js +++ b/Example/__tests__/App.test.tsx @@ -6,6 +6,9 @@ import 'react-native'; import React from 'react'; import App from '../App'; +// Note: import explicitly to use the types shiped with jest. +import {it} from '@jest/globals'; + // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; diff --git a/Example/android/app/BUCK b/Example/android/app/BUCK deleted file mode 100644 index a4cb8a5..0000000 --- a/Example/android/app/BUCK +++ /dev/null @@ -1,55 +0,0 @@ -# To learn about Buck see [Docs](https://buckbuild.com/). -# To run your application with Buck: -# - install Buck -# - `npm start` - to start the packager -# - `cd android` -# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` -# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck -# - `buck install -r android/app` - compile, install and run application -# - -load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") - -lib_deps = [] - -create_aar_targets(glob(["libs/*.aar"])) - -create_jar_targets(glob(["libs/*.jar"])) - -android_library( - name = "all-libs", - exported_deps = lib_deps, -) - -android_library( - name = "app-code", - srcs = glob([ - "src/main/java/**/*.java", - ]), - deps = [ - ":all-libs", - ":build_config", - ":res", - ], -) - -android_build_config( - name = "build_config", - package = "com.example", -) - -android_resource( - name = "res", - package = "com.example", - res = "src/main/res", -) - -android_binary( - name = "app", - keystore = "//android/keystores:debug", - manifest = "src/main/AndroidManifest.xml", - package_type = "debug", - deps = [ - ":app-code", - ], -) diff --git a/Example/android/app/build.gradle b/Example/android/app/build.gradle index 374e427..a3d064c 100644 --- a/Example/android/app/build.gradle +++ b/Example/android/app/build.gradle @@ -1,214 +1,85 @@ apply plugin: "com.android.application" - -import com.android.build.OutputFile -import org.apache.tools.ant.taskdefs.condition.Os +apply plugin: "com.facebook.react" /** - * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets - * and bundleReleaseJsAndAssets). - * These basically call `react-native bundle` with the correct arguments during the Android build - * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the - * bundle directly from the development server. Below you can see all the possible configurations - * and their defaults. If you decide to add a configuration block, make sure to add it before the - * `apply from: "../../node_modules/react-native/react.gradle"` line. - * - * project.ext.react = [ - * // the name of the generated asset file containing your JS bundle - * bundleAssetName: "index.android.bundle", - * - * // the entry file for bundle generation. If none specified and - * // "index.android.js" exists, it will be used. Otherwise "index.js" is - * // default. Can be overridden with ENTRY_FILE environment variable. - * entryFile: "index.android.js", - * - * // https://reactnative.dev/docs/performance#enable-the-ram-format - * bundleCommand: "ram-bundle", - * - * // whether to bundle JS and assets in debug mode - * bundleInDebug: false, - * - * // whether to bundle JS and assets in release mode - * bundleInRelease: true, - * - * // whether to bundle JS and assets in another build variant (if configured). - * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants - * // The configuration property can be in the following formats - * // 'bundleIn${productFlavor}${buildType}' - * // 'bundleIn${buildType}' - * // bundleInFreeDebug: true, - * // bundleInPaidRelease: true, - * // bundleInBeta: true, - * - * // whether to disable dev mode in custom build variants (by default only disabled in release) - * // for example: to disable dev mode in the staging build type (if configured) - * devDisabledInStaging: true, - * // The configuration property can be in the following formats - * // 'devDisabledIn${productFlavor}${buildType}' - * // 'devDisabledIn${buildType}' - * - * // the root of your project, i.e. where "package.json" lives - * root: "../../", - * - * // where to put the JS bundle asset in debug mode - * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", - * - * // where to put the JS bundle asset in release mode - * jsBundleDirRelease: "$buildDir/intermediates/assets/release", - * - * // where to put drawable resources / React Native assets, e.g. the ones you use via - * // require('./image.png')), in debug mode - * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", - * - * // where to put drawable resources / React Native assets, e.g. the ones you use via - * // require('./image.png')), in release mode - * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", - * - * // by default the gradle tasks are skipped if none of the JS files or assets change; this means - * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to - * // date; if you have any other folders that you want to ignore for performance reasons (gradle - * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ - * // for example, you might want to remove it from here. - * inputExcludes: ["android/**", "ios/**"], - * - * // override which node gets called and with what additional arguments - * nodeExecutableAndArgs: ["node"], - * - * // supply additional arguments to the packager - * extraPackagerArgs: [] - * ] + * This is the configuration block to customize your React Native Android app. + * By default you don't need to apply any configuration, just uncomment the lines you need. */ - -project.ext.react = [ - enableHermes: true, // clean and rebuild if changing -] - -apply from: "../../node_modules/react-native/react.gradle" - -/** - * Set this to true to create two separate APKs instead of one: - * - An APK that only works on ARM devices - * - An APK that only works on x86 devices - * The advantage is the size of the APK is reduced by about 4MB. - * Upload all the APKs to the Play Store and people will download - * the correct one based on the CPU architecture of their device. - */ -def enableSeparateBuildPerCPUArchitecture = false +react { + /* Folders */ + // The root of your project, i.e. where "package.json" lives. Default is '..' + // root = file("../") + // The folder where the react-native NPM package is. Default is ../node_modules/react-native + // reactNativeDir = file("../node_modules/react-native") + // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen + // codegenDir = file("../node_modules/@react-native/codegen") + // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js + // cliFile = file("../node_modules/react-native/cli.js") + + /* Variants */ + // The list of variants to that are debuggable. For those we're going to + // skip the bundling of the JS bundle and the assets. By default is just 'debug'. + // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. + // debuggableVariants = ["liteDebug", "prodDebug"] + + /* Bundling */ + // A list containing the node command and its flags. Default is just 'node'. + // nodeExecutableAndArgs = ["node"] + // + // The command to run when bundling. By default is 'bundle' + // bundleCommand = "ram-bundle" + // + // The path to the CLI configuration file. Default is empty. + // bundleConfig = file(../rn-cli.config.js) + // + // The name of the generated asset file containing your JS bundle + // bundleAssetName = "MyApplication.android.bundle" + // + // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' + // entryFile = file("../js/MyApplication.android.js") + // + // A list of extra flags to pass to the 'bundle' commands. + // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle + // extraPackagerArgs = [] + + /* Hermes Commands */ + // The hermes compiler command to run. By default it is 'hermesc' + // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" + // + // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" + // hermesFlags = ["-O", "-output-source-map"] +} /** - * Run Proguard to shrink the Java bytecode in release builds. + * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ def enableProguardInReleaseBuilds = false /** - * The preferred build flavor of JavaScriptCore. + * The preferred build flavor of JavaScriptCore (JSC) * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that - * give correct results when using with locales other than en-US. Note that + * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+' -/** - * Whether to enable the Hermes VM. - * - * This should be set on project.ext.react and that value will be read here. If it is not set - * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode - * and the benefits of using Hermes will therefore be sharply reduced. - */ -def enableHermes = project.ext.react.get("enableHermes", false); - -/** - * Architectures to build native code for. - */ -def reactNativeArchitectures() { - def value = project.getProperties().get("reactNativeArchitectures") - return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] -} - android { ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion + namespace "com.example" defaultConfig { applicationId "com.example" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" - buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() - - if (isNewArchitectureEnabled()) { - // We configure the CMake build only if you decide to opt-in for the New Architecture. - externalNativeBuild { - cmake { - arguments "-DPROJECT_BUILD_DIR=$buildDir", - "-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", - "-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build", - "-DNODE_MODULES_DIR=$rootDir/../node_modules", - "-DANDROID_STL=c++_shared" - } - } - if (!enableSeparateBuildPerCPUArchitecture) { - ndk { - abiFilters (*reactNativeArchitectures()) - } - } - } - } - - if (isNewArchitectureEnabled()) { - // We configure the NDK build only if you decide to opt-in for the New Architecture. - externalNativeBuild { - cmake { - path "$projectDir/src/main/jni/CMakeLists.txt" - } - } - def reactAndroidProjectDir = project(':ReactAndroid').projectDir - def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") - from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") - into("$buildDir/react-ndk/exported") - } - def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { - dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") - from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") - into("$buildDir/react-ndk/exported") - } - afterEvaluate { - // If you wish to add a custom TurboModule or component locally, - // you should uncomment this line. - // preBuild.dependsOn("generateCodegenArtifactsFromSchema") - preDebugBuild.dependsOn(packageReactNdkDebugLibs) - preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) - - // Due to a bug inside AGP, we have to explicitly set a dependency - // between configureCMakeDebug* tasks and the preBuild tasks. - // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 - configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) - configureCMakeDebug.dependsOn(preDebugBuild) - reactNativeArchitectures().each { architecture -> - tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { - dependsOn("preDebugBuild") - } - tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { - dependsOn("preReleaseBuild") - } - } - } - } - - splits { - abi { - reset() - enable enableSeparateBuildPerCPUArchitecture - universalApk false // If true, also generate a universal APK - include (*reactNativeArchitectures()) - } } signingConfigs { debug { @@ -230,84 +101,23 @@ android { proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } - - // applicationVariants are e.g. debug, release - applicationVariants.all { variant -> - variant.outputs.each { output -> - // For each separate APK per architecture, set a unique version code as described here: - // https://developer.android.com/studio/build/configure-apk-splits.html - // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. - def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] - def abi = output.getFilter(OutputFile.ABI) - if (abi != null) { // null for the universal-debug, universal-release variants - output.versionCodeOverride = - defaultConfig.versionCode * 1000 + versionCodes.get(abi) - } - - } - } } dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - - //noinspection GradleDynamicVersion - implementation "com.facebook.react:react-native:+" // From node_modules - - implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" - - debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { - exclude group:'com.facebook.fbjni' - } + // The version of react-native is set by the React Native Gradle Plugin + implementation("com.facebook.react:react-android") + debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' exclude group:'com.squareup.okhttp3', module:'okhttp' } - debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { - exclude group:'com.facebook.flipper' - } - - if (enableHermes) { - //noinspection GradleDynamicVersion - implementation("com.facebook.react:hermes-engine:+") { // From node_modules - exclude group:'com.facebook.fbjni' - } + debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") + if (hermesEnabled.toBoolean()) { + implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } } -if (isNewArchitectureEnabled()) { - // If new architecture is enabled, we let you build RN from source - // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. - // This will be applied to all the imported transtitive dependency. - configurations.all { - resolutionStrategy.dependencySubstitution { - substitute(module("com.facebook.react:react-native")) - .using(project(":ReactAndroid")) - .because("On New Architecture we're building React Native from source") - substitute(module("com.facebook.react:hermes-engine")) - .using(project(":ReactAndroid:hermes-engine")) - .because("On New Architecture we're building Hermes from source") - } - } -} - -// Run this once to be able to run the application with BUCK -// puts all compile dependencies into folder libs for BUCK to use -task copyDownloadableDepsToLibs(type: Copy) { - from configurations.implementation - into 'libs' -} - apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) - -def isNewArchitectureEnabled() { - // To opt-in for the New Architecture, you can either: - // - Set `newArchEnabled` to true inside the `gradle.properties` file - // - Invoke gradle with `-newArchEnabled=true` - // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" -} diff --git a/Example/android/app/build_defs.bzl b/Example/android/app/build_defs.bzl deleted file mode 100644 index fff270f..0000000 --- a/Example/android/app/build_defs.bzl +++ /dev/null @@ -1,19 +0,0 @@ -"""Helper definitions to glob .aar and .jar targets""" - -def create_aar_targets(aarfiles): - for aarfile in aarfiles: - name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] - lib_deps.append(":" + name) - android_prebuilt_aar( - name = name, - aar = aarfile, - ) - -def create_jar_targets(jarfiles): - for jarfile in jarfiles: - name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] - lib_deps.append(":" + name) - prebuilt_jar( - name = name, - binary_jar = jarfile, - ) diff --git a/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java b/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java index 9ffdd88..e75580e 100644 --- a/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +++ b/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java @@ -17,7 +17,6 @@ import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; -import com.facebook.flipper.plugins.react.ReactFlipperPlugin; import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; import com.facebook.react.ReactInstanceEventListener; import com.facebook.react.ReactInstanceManager; @@ -25,13 +24,16 @@ import com.facebook.react.modules.network.NetworkingModule; import okhttp3.OkHttpClient; +/** + * Class responsible of loading Flipper inside your React Native application. This is the debug + * flavor of it. Here you can add your own plugins and customize the Flipper setup. + */ public class ReactNativeFlipper { public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { if (FlipperUtils.shouldEnableFlipper(context)) { final FlipperClient client = AndroidFlipperClient.getInstance(context); client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); - client.addPlugin(new ReactFlipperPlugin()); client.addPlugin(new DatabasesFlipperPlugin(context)); client.addPlugin(new SharedPreferencesFlipperPlugin(context)); client.addPlugin(CrashReporterPlugin.getInstance()); diff --git a/Example/android/app/src/main/AndroidManifest.xml b/Example/android/app/src/main/AndroidManifest.xml index ef3c312..4122f36 100644 --- a/Example/android/app/src/main/AndroidManifest.xml +++ b/Example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/Example/android/app/src/main/java/com/example/MainActivity.java b/Example/android/app/src/main/java/com/example/MainActivity.java index bc5238f..fd92b73 100644 --- a/Example/android/app/src/main/java/com/example/MainActivity.java +++ b/Example/android/app/src/main/java/com/example/MainActivity.java @@ -2,7 +2,8 @@ import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; -import com.facebook.react.ReactRootView; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactActivityDelegate; public class MainActivity extends ReactActivity { @@ -16,33 +17,16 @@ protected String getMainComponentName() { } /** - * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and - * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer - * (Paper). + * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link + * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React + * (aka React 18) with two boolean flags. */ @Override protected ReactActivityDelegate createReactActivityDelegate() { - return new MainActivityDelegate(this, getMainComponentName()); - } - - public static class MainActivityDelegate extends ReactActivityDelegate { - public MainActivityDelegate(ReactActivity activity, String mainComponentName) { - super(activity, mainComponentName); - } - - @Override - protected ReactRootView createRootView() { - ReactRootView reactRootView = new ReactRootView(getContext()); - // If you opted-in for the New Architecture, we enable the Fabric Renderer. - reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); - return reactRootView; - } - - @Override - protected boolean isConcurrentRootEnabled() { - // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). - // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html - return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - } + return new DefaultReactActivityDelegate( + this, + getMainComponentName(), + // If you opted-in for the New Architecture, we enable the Fabric Renderer. + DefaultNewArchitectureEntryPoint.getFabricEnabled()); } } diff --git a/Example/android/app/src/main/java/com/example/MainApplication.java b/Example/android/app/src/main/java/com/example/MainApplication.java index 61f1d42..dd666be 100644 --- a/Example/android/app/src/main/java/com/example/MainApplication.java +++ b/Example/android/app/src/main/java/com/example/MainApplication.java @@ -1,22 +1,19 @@ package com.example; import android.app.Application; -import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; -import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; -import com.facebook.react.config.ReactFeatureFlags; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; +import com.facebook.react.defaults.DefaultReactNativeHost; import com.facebook.soloader.SoLoader; -import com.example.newarchitecture.MainApplicationReactNativeHost; -import java.lang.reflect.InvocationTargetException; import java.util.List; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = - new ReactNativeHost(this) { + new DefaultReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; @@ -35,57 +32,31 @@ protected List getPackages() { protected String getJSMainModuleName() { return "index"; } - }; - private final ReactNativeHost mNewArchitectureNativeHost = - new MainApplicationReactNativeHost(this); + @Override + protected boolean isNewArchEnabled() { + return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; + } + + @Override + protected Boolean isHermesEnabled() { + return BuildConfig.IS_HERMES_ENABLED; + } + }; @Override public ReactNativeHost getReactNativeHost() { - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - return mNewArchitectureNativeHost; - } else { - return mReactNativeHost; - } + return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); - // If you opted-in for the New Architecture, we enable the TurboModule system - ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; SoLoader.init(this, /* native exopackage */ false); - initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - } - - /** - * Loads Flipper in React Native templates. Call this in the onCreate method with something like - * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - * - * @param context - * @param reactInstanceManager - */ - private static void initializeFlipper( - Context context, ReactInstanceManager reactInstanceManager) { - if (BuildConfig.DEBUG) { - try { - /* - We use reflection here to pick up the class that initializes Flipper, - since Flipper library is not available in release mode - */ - Class aClass = Class.forName("com.example.ReactNativeFlipper"); - aClass - .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) - .invoke(null, context, reactInstanceManager); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } + if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { + // If you opted-in for the New Architecture, we load the native entry point for this app. + DefaultNewArchitectureEntryPoint.load(); } + ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } } diff --git a/Example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java b/Example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java deleted file mode 100644 index 68aea28..0000000 --- a/Example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.example.newarchitecture; - -import android.app.Application; -import androidx.annotation.NonNull; -import com.facebook.react.PackageList; -import com.facebook.react.ReactInstanceManager; -import com.facebook.react.ReactNativeHost; -import com.facebook.react.ReactPackage; -import com.facebook.react.ReactPackageTurboModuleManagerDelegate; -import com.facebook.react.bridge.JSIModulePackage; -import com.facebook.react.bridge.JSIModuleProvider; -import com.facebook.react.bridge.JSIModuleSpec; -import com.facebook.react.bridge.JSIModuleType; -import com.facebook.react.bridge.JavaScriptContextHolder; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.UIManager; -import com.facebook.react.fabric.ComponentFactory; -import com.facebook.react.fabric.CoreComponentsRegistry; -import com.facebook.react.fabric.FabricJSIModuleProvider; -import com.facebook.react.fabric.ReactNativeConfig; -import com.facebook.react.uimanager.ViewManagerRegistry; -import com.example.BuildConfig; -import com.example.newarchitecture.components.MainComponentsRegistry; -import com.example.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; -import java.util.ArrayList; -import java.util.List; - -/** - * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both - * TurboModule delegates and the Fabric Renderer. - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -public class MainApplicationReactNativeHost extends ReactNativeHost { - public MainApplicationReactNativeHost(Application application) { - super(application); - } - - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - - @Override - protected List getPackages() { - List packages = new PackageList(this).getPackages(); - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: - // packages.add(new TurboReactPackage() { ... }); - // If you have custom Fabric Components, their ViewManagers should also be loaded here - // inside a ReactPackage. - return packages; - } - - @Override - protected String getJSMainModuleName() { - return "index"; - } - - @NonNull - @Override - protected ReactPackageTurboModuleManagerDelegate.Builder - getReactPackageTurboModuleManagerDelegateBuilder() { - // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary - // for the new architecture and to use TurboModules correctly. - return new MainApplicationTurboModuleManagerDelegate.Builder(); - } - - @Override - protected JSIModulePackage getJSIModulePackage() { - return new JSIModulePackage() { - @Override - public List getJSIModules( - final ReactApplicationContext reactApplicationContext, - final JavaScriptContextHolder jsContext) { - final List specs = new ArrayList<>(); - - // Here we provide a new JSIModuleSpec that will be responsible of providing the - // custom Fabric Components. - specs.add( - new JSIModuleSpec() { - @Override - public JSIModuleType getJSIModuleType() { - return JSIModuleType.UIManager; - } - - @Override - public JSIModuleProvider getJSIModuleProvider() { - final ComponentFactory componentFactory = new ComponentFactory(); - CoreComponentsRegistry.register(componentFactory); - - // Here we register a Components Registry. - // The one that is generated with the template contains no components - // and just provides you the one from React Native core. - MainComponentsRegistry.register(componentFactory); - - final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); - - ViewManagerRegistry viewManagerRegistry = - new ViewManagerRegistry( - reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); - - return new FabricJSIModuleProvider( - reactApplicationContext, - componentFactory, - ReactNativeConfig.DEFAULT_CONFIG, - viewManagerRegistry); - } - }); - return specs; - } - }; - } -} diff --git a/Example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java b/Example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java deleted file mode 100644 index 98ff973..0000000 --- a/Example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.example.newarchitecture.components; - -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.fabric.ComponentFactory; -import com.facebook.soloader.SoLoader; - -/** - * Class responsible to load the custom Fabric Components. This class has native methods and needs a - * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ - * folder for you). - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -@DoNotStrip -public class MainComponentsRegistry { - static { - SoLoader.loadLibrary("fabricjni"); - } - - @DoNotStrip private final HybridData mHybridData; - - @DoNotStrip - private native HybridData initHybrid(ComponentFactory componentFactory); - - @DoNotStrip - private MainComponentsRegistry(ComponentFactory componentFactory) { - mHybridData = initHybrid(componentFactory); - } - - @DoNotStrip - public static MainComponentsRegistry register(ComponentFactory componentFactory) { - return new MainComponentsRegistry(componentFactory); - } -} diff --git a/Example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java b/Example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java deleted file mode 100644 index b30c50e..0000000 --- a/Example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.example.newarchitecture.modules; - -import com.facebook.jni.HybridData; -import com.facebook.react.ReactPackage; -import com.facebook.react.ReactPackageTurboModuleManagerDelegate; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.soloader.SoLoader; -import java.util.List; - -/** - * Class responsible to load the TurboModules. This class has native methods and needs a - * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ - * folder for you). - * - *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the - * `newArchEnabled` property). Is ignored otherwise. - */ -public class MainApplicationTurboModuleManagerDelegate - extends ReactPackageTurboModuleManagerDelegate { - - private static volatile boolean sIsSoLibraryLoaded; - - protected MainApplicationTurboModuleManagerDelegate( - ReactApplicationContext reactApplicationContext, List packages) { - super(reactApplicationContext, packages); - } - - protected native HybridData initHybrid(); - - native boolean canCreateTurboModule(String moduleName); - - public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { - protected MainApplicationTurboModuleManagerDelegate build( - ReactApplicationContext context, List packages) { - return new MainApplicationTurboModuleManagerDelegate(context, packages); - } - } - - @Override - protected synchronized void maybeLoadOtherSoLibraries() { - if (!sIsSoLibraryLoaded) { - // If you change the name of your application .so file in the Android.mk file, - // make sure you update the name here as well. - SoLoader.loadLibrary("example_appmodules"); - sIsSoLibraryLoaded = true; - } - } -} diff --git a/Example/android/app/src/main/jni/CMakeLists.txt b/Example/android/app/src/main/jni/CMakeLists.txt deleted file mode 100644 index 9abdd49..0000000 --- a/Example/android/app/src/main/jni/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.13) - -# Define the library name here. -project(example_appmodules) - -# This file includes all the necessary to let you build your application with the New Architecture. -include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake) diff --git a/Example/android/app/src/main/jni/MainApplicationModuleProvider.cpp b/Example/android/app/src/main/jni/MainApplicationModuleProvider.cpp deleted file mode 100644 index 26162dd..0000000 --- a/Example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "MainApplicationModuleProvider.h" - -#include -#include - -namespace facebook { -namespace react { - -std::shared_ptr MainApplicationModuleProvider( - const std::string &moduleName, - const JavaTurboModule::InitParams ¶ms) { - // Here you can provide your own module provider for TurboModules coming from - // either your application or from external libraries. The approach to follow - // is similar to the following (for a library called `samplelibrary`: - // - // auto module = samplelibrary_ModuleProvider(moduleName, params); - // if (module != nullptr) { - // return module; - // } - // return rncore_ModuleProvider(moduleName, params); - - // Module providers autolinked by RN CLI - auto rncli_module = rncli_ModuleProvider(moduleName, params); - if (rncli_module != nullptr) { - return rncli_module; - } - - return rncore_ModuleProvider(moduleName, params); -} - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/MainApplicationModuleProvider.h b/Example/android/app/src/main/jni/MainApplicationModuleProvider.h deleted file mode 100644 index b38ccf5..0000000 --- a/Example/android/app/src/main/jni/MainApplicationModuleProvider.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace facebook { -namespace react { - -std::shared_ptr MainApplicationModuleProvider( - const std::string &moduleName, - const JavaTurboModule::InitParams ¶ms); - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp b/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp deleted file mode 100644 index 5fd688c..0000000 --- a/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "MainApplicationTurboModuleManagerDelegate.h" -#include "MainApplicationModuleProvider.h" - -namespace facebook { -namespace react { - -jni::local_ref -MainApplicationTurboModuleManagerDelegate::initHybrid( - jni::alias_ref) { - return makeCxxInstance(); -} - -void MainApplicationTurboModuleManagerDelegate::registerNatives() { - registerHybrid({ - makeNativeMethod( - "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), - makeNativeMethod( - "canCreateTurboModule", - MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), - }); -} - -std::shared_ptr -MainApplicationTurboModuleManagerDelegate::getTurboModule( - const std::string &name, - const std::shared_ptr &jsInvoker) { - // Not implemented yet: provide pure-C++ NativeModules here. - return nullptr; -} - -std::shared_ptr -MainApplicationTurboModuleManagerDelegate::getTurboModule( - const std::string &name, - const JavaTurboModule::InitParams ¶ms) { - return MainApplicationModuleProvider(name, params); -} - -bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( - const std::string &name) { - return getTurboModule(name, nullptr) != nullptr || - getTurboModule(name, {.moduleName = name}) != nullptr; -} - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h b/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h deleted file mode 100644 index 0ef746b..0000000 --- a/Example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -#include -#include - -namespace facebook { -namespace react { - -class MainApplicationTurboModuleManagerDelegate - : public jni::HybridClass< - MainApplicationTurboModuleManagerDelegate, - TurboModuleManagerDelegate> { - public: - // Adapt it to the package you used for your Java class. - static constexpr auto kJavaDescriptor = - "Lcom/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; - - static jni::local_ref initHybrid(jni::alias_ref); - - static void registerNatives(); - - std::shared_ptr getTurboModule( - const std::string &name, - const std::shared_ptr &jsInvoker) override; - std::shared_ptr getTurboModule( - const std::string &name, - const JavaTurboModule::InitParams ¶ms) override; - - /** - * Test-only method. Allows user to verify whether a TurboModule can be - * created by instances of this class. - */ - bool canCreateTurboModule(const std::string &name); -}; - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/MainComponentsRegistry.cpp b/Example/android/app/src/main/jni/MainComponentsRegistry.cpp deleted file mode 100644 index 54f598a..0000000 --- a/Example/android/app/src/main/jni/MainComponentsRegistry.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "MainComponentsRegistry.h" - -#include -#include -#include -#include -#include - -namespace facebook { -namespace react { - -MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} - -std::shared_ptr -MainComponentsRegistry::sharedProviderRegistry() { - auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); - - // Autolinked providers registered by RN CLI - rncli_registerProviders(providerRegistry); - - // Custom Fabric Components go here. You can register custom - // components coming from your App or from 3rd party libraries here. - // - // providerRegistry->add(concreteComponentDescriptorProvider< - // AocViewerComponentDescriptor>()); - return providerRegistry; -} - -jni::local_ref -MainComponentsRegistry::initHybrid( - jni::alias_ref, - ComponentFactory *delegate) { - auto instance = makeCxxInstance(delegate); - - auto buildRegistryFunction = - [](EventDispatcher::Weak const &eventDispatcher, - ContextContainer::Shared const &contextContainer) - -> ComponentDescriptorRegistry::Shared { - auto registry = MainComponentsRegistry::sharedProviderRegistry() - ->createComponentDescriptorRegistry( - {eventDispatcher, contextContainer}); - - auto mutableRegistry = - std::const_pointer_cast(registry); - - mutableRegistry->setFallbackComponentDescriptor( - std::make_shared( - ComponentDescriptorParameters{ - eventDispatcher, contextContainer, nullptr})); - - return registry; - }; - - delegate->buildRegistryFunction = buildRegistryFunction; - return instance; -} - -void MainComponentsRegistry::registerNatives() { - registerHybrid({ - makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), - }); -} - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/MainComponentsRegistry.h b/Example/android/app/src/main/jni/MainComponentsRegistry.h deleted file mode 100644 index 23a9cac..0000000 --- a/Example/android/app/src/main/jni/MainComponentsRegistry.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace facebook { -namespace react { - -class MainComponentsRegistry - : public facebook::jni::HybridClass { - public: - // Adapt it to the package you used for your Java class. - constexpr static auto kJavaDescriptor = - "Lcom/example/newarchitecture/components/MainComponentsRegistry;"; - - static void registerNatives(); - - MainComponentsRegistry(ComponentFactory *delegate); - - private: - static std::shared_ptr - sharedProviderRegistry(); - - static jni::local_ref initHybrid( - jni::alias_ref, - ComponentFactory *delegate); -}; - -} // namespace react -} // namespace facebook diff --git a/Example/android/app/src/main/jni/OnLoad.cpp b/Example/android/app/src/main/jni/OnLoad.cpp deleted file mode 100644 index c569b6e..0000000 --- a/Example/android/app/src/main/jni/OnLoad.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "MainApplicationTurboModuleManagerDelegate.h" -#include "MainComponentsRegistry.h" - -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { - return facebook::jni::initialize(vm, [] { - facebook::react::MainApplicationTurboModuleManagerDelegate:: - registerNatives(); - facebook::react::MainComponentsRegistry::registerNatives(); - }); -} diff --git a/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml b/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml index f35d996..73b37e4 100644 --- a/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml +++ b/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml @@ -20,7 +20,7 @@ android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"> -