Skip to content

Commit 4ddccf5

Browse files
feat: support both new + old arch
1 parent 5750927 commit 4ddccf5

File tree

10 files changed

+169
-93
lines changed

10 files changed

+169
-93
lines changed

android/build.gradle

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ buildscript {
1919
apply plugin: "com.android.library"
2020
apply plugin: "kotlin-android"
2121

22-
apply plugin: "com.facebook.react"
22+
if (isNewArchitectureEnabled()) {
23+
apply plugin: "com.facebook.react"
24+
}
2325

2426
def getExtOrIntegerDefault(name) {
2527
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LoaderKit_" + name]).toInteger()
2628
}
2729

30+
def isNewArchitectureEnabled() {
31+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
32+
}
33+
34+
2835
android {
2936
namespace "com.loaderkit"
3037

@@ -33,6 +40,7 @@ android {
3340
defaultConfig {
3441
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
3542
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
43+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
3644
}
3745

3846
buildFeatures {
@@ -56,10 +64,16 @@ android {
5664

5765
sourceSets {
5866
main {
59-
java.srcDirs += [
60-
"generated/java",
61-
"generated/jni"
62-
]
67+
if (isNewArchitectureEnabled()) {
68+
java.srcDirs += [
69+
"src/newarch",
70+
// Codegen specs
71+
"generated/java",
72+
"generated/jni"
73+
]
74+
} else {
75+
java.srcDirs += "src/oldarch"
76+
}
6377
}
6478
}
6579
}
@@ -77,8 +91,10 @@ dependencies {
7791
implementation "io.github.maitrungduc1410:AVLoadingIndicatorView:2.3.0"
7892
}
7993

80-
react {
81-
jsRootDir = file("../src/")
82-
libraryName = "LoaderKitView"
83-
codegenJavaPackageName = "com.loaderkit"
94+
if (isNewArchitectureEnabled()) {
95+
react {
96+
jsRootDir = file("../src/")
97+
libraryName = "LoaderKitView"
98+
codegenJavaPackageName = "com.loaderkit"
99+
}
84100
}

android/src/main/java/com/loaderkit/LoaderKitView.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

android/src/main/java/com/loaderkit/LoaderKitViewManager.kt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@ package com.loaderkit
22

33
import android.graphics.Color
44
import com.facebook.react.module.annotations.ReactModule
5-
import com.facebook.react.uimanager.SimpleViewManager
65
import com.facebook.react.uimanager.ThemedReactContext
7-
import com.facebook.react.uimanager.ViewManagerDelegate
86
import com.facebook.react.uimanager.annotations.ReactProp
9-
import com.facebook.react.viewmanagers.LoaderKitViewManagerInterface
10-
import com.facebook.react.viewmanagers.LoaderKitViewManagerDelegate
7+
import com.testrncompatview.LoaderKitViewManagerSpec
118
import com.wang.avi.AVLoadingIndicatorView;
129

1310
@ReactModule(name = LoaderKitViewManager.NAME)
14-
class LoaderKitViewManager : SimpleViewManager<AVLoadingIndicatorView>(),
15-
LoaderKitViewManagerInterface<AVLoadingIndicatorView> {
16-
private val mDelegate: ViewManagerDelegate<AVLoadingIndicatorView>
17-
18-
init {
19-
mDelegate = LoaderKitViewManagerDelegate(this)
20-
}
21-
22-
override fun getDelegate(): ViewManagerDelegate<AVLoadingIndicatorView>? {
23-
return mDelegate
24-
}
11+
class LoaderKitViewManager : LoaderKitViewManagerSpec<AVLoadingIndicatorView>() {
2512

2613
override fun getName(): String {
2714
return NAME
@@ -32,15 +19,15 @@ class LoaderKitViewManager : SimpleViewManager<AVLoadingIndicatorView>(),
3219
}
3320

3421
@ReactProp(name = "name")
35-
override fun setName(view: AVLoadingIndicatorView?, name: String?) {
36-
name?.let {
22+
override fun setName(view: AVLoadingIndicatorView?, value: String?) {
23+
value?.let {
3724
view?.setIndicator("${it}Indicator")
3825
}
3926
}
4027

4128
@ReactProp(name = "color", defaultInt = Color.WHITE)
42-
override fun setColor(view: AVLoadingIndicatorView?, color: Int) {
43-
view?.setIndicatorColor(color)
29+
override fun setColor(view: AVLoadingIndicatorView?, value: Int) {
30+
view?.setIndicatorColor(value)
4431
}
4532

4633
@ReactProp(name = "animationSpeedMultiplier", defaultFloat = 1f)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.testrncompatview
2+
3+
import android.view.View
4+
5+
import com.facebook.react.uimanager.SimpleViewManager
6+
import com.facebook.react.uimanager.ViewManagerDelegate
7+
import com.facebook.react.viewmanagers.LoaderKitViewManagerDelegate
8+
import com.facebook.react.viewmanagers.LoaderKitViewManagerInterface
9+
10+
abstract class LoaderKitViewManagerSpec<T : View> : SimpleViewManager<T>(), LoaderKitViewManagerInterface<T> {
11+
private val mDelegate: ViewManagerDelegate<T> = LoaderKitViewManagerDelegate(this)
12+
13+
override fun getDelegate(): ViewManagerDelegate<T>? {
14+
return mDelegate
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.testrncompatview
2+
3+
import android.view.View
4+
import com.facebook.react.uimanager.SimpleViewManager
5+
6+
abstract class LoaderKitViewManagerSpec<T : View> : SimpleViewManager<T>() {
7+
abstract fun setColor(view: T?, value: Int)
8+
abstract fun setName(view: T?, value: String?)
9+
abstract fun setAnimationSpeedMultiplier(view: T?, value: Float)
10+
}

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
1+
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
22

33
# Resolve react_native_pods.rb with node to allow for hoisting
44
require Pod::Executable.execute_command('node', ['-p',

example/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- hermes-engine (0.79.2):
99
- hermes-engine/Pre-built (= 0.79.2)
1010
- hermes-engine/Pre-built (0.79.2)
11-
- LoaderKit (0.1.0):
11+
- LoaderKit (3.0.0):
1212
- DoubleConversion
1313
- glog
1414
- hermes-engine
@@ -1916,7 +1916,7 @@ SPEC CHECKSUMS:
19161916
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
19171917
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
19181918
hermes-engine: 314be5250afa5692b57b4dd1705959e1973a8ebe
1919-
LoaderKit: d1bfefd29c001be3626e8372440eaa0fade5415c
1919+
LoaderKit: 984fcf908338cee4137a65115a0f44df26e9754a
19201920
NVActivityIndicatorView-ObjC: a2394f53d84c32f71823743a2030e0378d40332f
19211921
RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809
19221922
RCTDeprecation: 83ffb90c23ee5cea353bd32008a7bca100908f8c
@@ -1955,14 +1955,14 @@ SPEC CHECKSUMS:
19551955
React-performancetimeline: abf31259d794c9274b3ea19c5016186925eec6c4
19561956
React-RCTActionSheet: a499b0d6d9793886b67ba3e16046a3fef2cdbbc3
19571957
React-RCTAnimation: 2595dcb10a82216a511b54742f8c28d793852ac6
1958-
React-RCTAppDelegate: f03604b70f57c9469a84a159d8abecf793a5bcff
1958+
React-RCTAppDelegate: 680583cfafce8d9d80e56d20915348a63499fc39
19591959
React-RCTBlob: e00f9b4e2f151938f4d9864cf33ebf24ac03328a
1960-
React-RCTFabric: 3945d116fd271598db262d4e6ed5691d431ed9e8
1961-
React-RCTFBReactNativeSpec: 0f4d4f0da938101f2ca9d5333a8f46e527ad2819
1960+
React-RCTFabric: 39dae0812c3faae0dd5e20c31bc51d8ee7759787
1961+
React-RCTFBReactNativeSpec: ec90b9c2b684ab5622511618bf078fcad502690c
19621962
React-RCTImage: dac5e9f8ec476aefe6e60ee640ebc1dfaf1a4dbe
19631963
React-RCTLinking: 494b785a40d952a1dfbe712f43214376e5f0e408
19641964
React-RCTNetwork: b3d7c30cd21793e268db107dd0980cb61b3c1c44
1965-
React-RCTRuntime: a8ff419d437228e7b8a793b14f9d711e1cbb82af
1965+
React-RCTRuntime: 87e560264bb9b3eb3fc621b3071353f21c7ce381
19661966
React-RCTSettings: a060c7e381a3896104761b8eed7e284d95e37df3
19671967
React-RCTText: 4f272b72dbb61f390d8c8274528f9fdbff983806
19681968
React-RCTVibration: 0e5326220719aca12473d703aa46693e3b4ce67a
@@ -1983,6 +1983,6 @@ SPEC CHECKSUMS:
19831983
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19841984
Yoga: 9f110fc4b7aa538663cba3c14cbb1c335f43c13f
19851985

1986-
PODFILE CHECKSUM: 286c2dc2f5d707fd37bdf1c66cdd1c0526041c17
1986+
PODFILE CHECKSUM: 6cef6942ccf18fe8e571406c1c885d224c1eb48c
19871987

1988-
COCOAPODS: 1.15.2
1988+
COCOAPODS: 1.16.2

ios/LoaderKitView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
12
#import <React/RCTViewComponentView.h>
23
#import <UIKit/UIKit.h>
34

@@ -12,3 +13,12 @@ NS_ASSUME_NONNULL_BEGIN
1213
NS_ASSUME_NONNULL_END
1314

1415
#endif /* LoaderKitViewNativeComponent_h */
16+
17+
#else
18+
19+
#import "React/RCTViewManager.h"
20+
21+
@interface LoaderKitViewManager : RCTViewManager
22+
@end
23+
24+
#endif

ios/LoaderKitView.mm

Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
#import "LoaderKitView.h"
2+
#import "NVActivityIndicatorView.h"
3+
#import "React/RCTConvert.h"
4+
5+
static const NSDictionary *nameToTypeMap = @{
6+
@"BallPulse": @(NVActivityIndicatorTypeBallPulse),
7+
@"BallGridPulse": @(NVActivityIndicatorTypeBallGridPulse),
8+
@"BallClipRotate": @(NVActivityIndicatorTypeBallClipRotate),
9+
@"SquareSpin": @(NVActivityIndicatorTypeSquareSpin),
10+
@"BallClipRotatePulse": @(NVActivityIndicatorTypeBallClipRotatePulse),
11+
@"BallClipRotateMultiple": @(NVActivityIndicatorTypeBallClipRotateMultiple),
12+
@"BallPulseRise": @(NVActivityIndicatorTypeBallPulseRise),
13+
@"BallRotate": @(NVActivityIndicatorTypeBallRotate),
14+
@"CubeTransition": @(NVActivityIndicatorTypeCubeTransition),
15+
@"BallZigZag": @(NVActivityIndicatorTypeBallZigZag),
16+
@"BallZigZagDeflect": @(NVActivityIndicatorTypeBallZigZagDeflect),
17+
@"BallTrianglePath": @(NVActivityIndicatorTypeBallTrianglePath),
18+
@"BallScale": @(NVActivityIndicatorTypeBallScale),
19+
@"LineScale": @(NVActivityIndicatorTypeLineScale),
20+
@"LineScaleParty": @(NVActivityIndicatorTypeLineScaleParty),
21+
@"BallScaleMultiple": @(NVActivityIndicatorTypeBallScaleMultiple),
22+
@"BallPulseSync": @(NVActivityIndicatorTypeBallPulseSync),
23+
@"BallBeat": @(NVActivityIndicatorTypeBallBeat),
24+
@"LineScalePulseOut": @(NVActivityIndicatorTypeLineScalePulseOut),
25+
@"LineScalePulseOutRapid": @(NVActivityIndicatorTypeLineScalePulseOutRapid),
26+
@"BallScaleRipple": @(NVActivityIndicatorTypeBallScaleRipple),
27+
@"BallScaleRippleMultiple": @(NVActivityIndicatorTypeBallScaleRippleMultiple),
28+
@"BallSpinFadeLoader": @(NVActivityIndicatorTypeBallSpinFadeLoader),
29+
@"LineSpinFadeLoader": @(NVActivityIndicatorTypeLineSpinFadeLoader),
30+
@"TriangleSkewSpin": @(NVActivityIndicatorTypeTriangleSkewSpin),
31+
@"Pacman": @(NVActivityIndicatorTypePacman),
32+
@"BallGridBeat": @(NVActivityIndicatorTypeBallGridBeat),
33+
@"SemiCircleSpin": @(NVActivityIndicatorTypeSemiCircleSpin),
34+
@"BallRotateChase": @(NVActivityIndicatorTypeBallRotateChase),
35+
@"Orbit": @(NVActivityIndicatorTypeOrbit),
36+
@"AudioEqualizer": @(NVActivityIndicatorTypeAudioEqualizer),
37+
@"CircleStrokeSpin": @(NVActivityIndicatorTypeCircleStrokeSpin),
38+
@"BallDoubleBounce": @(NVActivityIndicatorTypeBallDoubleBounce)
39+
};
40+
41+
#ifdef RCT_NEW_ARCH_ENABLED
242

343
#import <react/renderer/components/LoaderKitViewSpec/ComponentDescriptors.h>
444
#import <react/renderer/components/LoaderKitViewSpec/EventEmitters.h>
@@ -7,9 +47,6 @@
747

848
#import "RCTFabricComponentsPlugins.h"
949

10-
#import "NVActivityIndicatorView.h"
11-
#import <React/RCTConvert.h>
12-
1350
using namespace facebook::react;
1451

1552
@interface LoaderKitView () <RCTLoaderKitViewViewProtocol>
@@ -70,50 +107,65 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
70107
- (NVActivityIndicatorType)getIndicatorTypeFromName:(NSString *)name
71108
{
72109
if (!name) return NVActivityIndicatorTypeBallPulse;
110+
111+
NSNumber *typeNumber = nameToTypeMap[name];
112+
if (typeNumber) {
113+
return (NVActivityIndicatorType)[typeNumber integerValue];
114+
}
73115

74-
// Map indicator names to types (matching the Android names)
75-
NSDictionary *nameToTypeMap = @{
76-
@"BallPulse": @(NVActivityIndicatorTypeBallPulse),
77-
@"BallGridPulse": @(NVActivityIndicatorTypeBallGridPulse),
78-
@"BallClipRotate": @(NVActivityIndicatorTypeBallClipRotate),
79-
@"SquareSpin": @(NVActivityIndicatorTypeSquareSpin),
80-
@"BallClipRotatePulse": @(NVActivityIndicatorTypeBallClipRotatePulse),
81-
@"BallClipRotateMultiple": @(NVActivityIndicatorTypeBallClipRotateMultiple),
82-
@"BallPulseRise": @(NVActivityIndicatorTypeBallPulseRise),
83-
@"BallRotate": @(NVActivityIndicatorTypeBallRotate),
84-
@"CubeTransition": @(NVActivityIndicatorTypeCubeTransition),
85-
@"BallZigZag": @(NVActivityIndicatorTypeBallZigZag),
86-
@"BallZigZagDeflect": @(NVActivityIndicatorTypeBallZigZagDeflect),
87-
@"BallTrianglePath": @(NVActivityIndicatorTypeBallTrianglePath),
88-
@"BallScale": @(NVActivityIndicatorTypeBallScale),
89-
@"LineScale": @(NVActivityIndicatorTypeLineScale),
90-
@"LineScaleParty": @(NVActivityIndicatorTypeLineScaleParty),
91-
@"BallScaleMultiple": @(NVActivityIndicatorTypeBallScaleMultiple),
92-
@"BallPulseSync": @(NVActivityIndicatorTypeBallPulseSync),
93-
@"BallBeat": @(NVActivityIndicatorTypeBallBeat),
94-
@"LineScalePulseOut": @(NVActivityIndicatorTypeLineScalePulseOut),
95-
@"LineScalePulseOutRapid": @(NVActivityIndicatorTypeLineScalePulseOutRapid),
96-
@"BallScaleRipple": @(NVActivityIndicatorTypeBallScaleRipple),
97-
@"BallScaleRippleMultiple": @(NVActivityIndicatorTypeBallScaleRippleMultiple),
98-
@"BallSpinFadeLoader": @(NVActivityIndicatorTypeBallSpinFadeLoader),
99-
@"LineSpinFadeLoader": @(NVActivityIndicatorTypeLineSpinFadeLoader),
100-
@"TriangleSkewSpin": @(NVActivityIndicatorTypeTriangleSkewSpin),
101-
@"Pacman": @(NVActivityIndicatorTypePacman),
102-
@"BallGridBeat": @(NVActivityIndicatorTypeBallGridBeat),
103-
@"SemiCircleSpin": @(NVActivityIndicatorTypeSemiCircleSpin),
104-
@"BallRotateChase": @(NVActivityIndicatorTypeBallRotateChase),
105-
@"Orbit": @(NVActivityIndicatorTypeOrbit),
106-
@"AudioEqualizer": @(NVActivityIndicatorTypeAudioEqualizer),
107-
@"CircleStrokeSpin": @(NVActivityIndicatorTypeCircleStrokeSpin),
108-
@"BallDoubleBounce": @(NVActivityIndicatorTypeBallDoubleBounce)
109-
};
116+
return NVActivityIndicatorTypeBallPulse; // Default fallback
117+
}
118+
119+
@end
120+
121+
#else
122+
123+
@implementation LoaderKitViewManager
124+
125+
RCT_EXPORT_MODULE(LoaderKitView)
126+
127+
- (UIView *)view
128+
{
129+
return [[NVActivityIndicatorView alloc] init];
130+
}
131+
132+
- (NVActivityIndicatorType)getIndicatorTypeFromName:(NSString *)name
133+
{
134+
if (!name) return NVActivityIndicatorTypeBallPulse;
110135

111136
NSNumber *typeNumber = nameToTypeMap[name];
112137
if (typeNumber) {
113138
return (NVActivityIndicatorType)[typeNumber integerValue];
114139
}
115140

116-
return NVActivityIndicatorTypeBallPulse; // Default fallback
141+
return NVActivityIndicatorTypeBallPulse;
142+
}
143+
144+
RCT_CUSTOM_VIEW_PROPERTY(name, NSString, NVActivityIndicatorView)
145+
{
146+
NSString *indicatorName = [RCTConvert NSString:json];
147+
if (indicatorName) {
148+
NVActivityIndicatorType type = [self getIndicatorTypeFromName:indicatorName];
149+
view.type = type;
150+
}
151+
}
152+
153+
RCT_CUSTOM_VIEW_PROPERTY(color, UIColor, NVActivityIndicatorView)
154+
{
155+
UIColor *color = [RCTConvert UIColor:json];
156+
if (color) {
157+
view.color = color;
158+
}
159+
}
160+
161+
RCT_CUSTOM_VIEW_PROPERTY(animationSpeedMultiplier, CGFloat, NVActivityIndicatorView)
162+
{
163+
CGFloat speedMultiplier = [RCTConvert CGFloat:json];
164+
view.animationSpeedMultiplier = speedMultiplier;
117165
}
118166

119167
@end
168+
169+
#endif
170+
171+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-loader-kit",
3-
"version": "3.0.0",
3+
"version": "4.0.0",
44
"description": "🎯 Beautiful native loading indicators for React Native with 30+ animations, TypeScript support, and speed control",
55
"main": "./lib/module/index.js",
66
"types": "./lib/typescript/src/index.d.ts",

0 commit comments

Comments
 (0)