gt-react-native 0.0.1-alpha.2 → 0.0.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,16 @@ buildscript {
15
15
  }
16
16
  }
17
17
 
18
+ def isNewArchitectureEnabled() {
19
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
20
+ }
18
21
 
19
22
  apply plugin: "com.android.library"
20
23
  apply plugin: "kotlin-android"
21
24
 
22
- apply plugin: "com.facebook.react"
25
+ if (isNewArchitectureEnabled()) {
26
+ apply plugin: "com.facebook.react"
27
+ }
23
28
 
24
29
  def getExtOrIntegerDefault(name) {
25
30
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["GtReactNative_" + name]).toInteger()
@@ -31,6 +36,7 @@ android {
31
36
  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
37
 
33
38
  defaultConfig {
39
+ buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
34
40
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
41
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
42
  }
@@ -60,6 +66,11 @@ android {
60
66
  "generated/java",
61
67
  "generated/jni"
62
68
  ]
69
+ if (isNewArchitectureEnabled()) {
70
+ java.srcDirs += ["src/newarch"]
71
+ } else {
72
+ java.srcDirs += ["src/oldarch"]
73
+ }
63
74
  }
64
75
  }
65
76
  }
@@ -6,28 +6,16 @@ import android.os.LocaleList
6
6
  import com.facebook.react.bridge.Arguments
7
7
  import com.facebook.react.bridge.ReactApplicationContext
8
8
  import com.facebook.react.bridge.WritableArray
9
- import com.facebook.react.module.annotations.ReactModule
10
9
  import java.util.Locale
11
10
 
12
- @ReactModule(name = GtReactNativeModule.NAME)
13
- class GtReactNativeModule(reactContext: ReactApplicationContext) :
14
- NativeGtReactNativeSpec(reactContext) {
11
+ object GtReactNativeModuleImpl {
12
+ const val NAME = "GtReactNative"
15
13
 
16
- private val prefs by lazy {
17
- reactApplicationContext.getSharedPreferences("gt_store", Context.MODE_PRIVATE)
18
- }
19
-
20
- override fun getName(): String {
21
- return NAME
22
- }
23
-
24
- // Example method
25
- // See https://reactnative.dev/docs/native-modules-android
26
- override fun multiply(a: Double, b: Double): Double {
14
+ fun multiply(a: Double, b: Double): Double {
27
15
  return a * b
28
16
  }
29
17
 
30
- override fun getNativeLocales(): WritableArray {
18
+ fun getNativeLocales(reactContext: ReactApplicationContext): WritableArray {
31
19
  val locales = Arguments.createArray()
32
20
  val seenLocales = mutableSetOf<String>()
33
21
 
@@ -56,13 +44,13 @@ class GtReactNativeModule(reactContext: ReactApplicationContext) :
56
44
  return locales
57
45
  }
58
46
 
59
- override fun nativeStoreGet(key: String): String? = prefs.getString(key, null)
60
-
61
- override fun nativeStoreSet(key: String, value: String) {
62
- prefs.edit().putString(key, value).apply()
47
+ fun nativeStoreGet(reactContext: ReactApplicationContext, key: String): String? {
48
+ val prefs = reactContext.getSharedPreferences("gt_store", Context.MODE_PRIVATE)
49
+ return prefs.getString(key, null)
63
50
  }
64
51
 
65
- companion object {
66
- const val NAME = "GtReactNative"
52
+ fun nativeStoreSet(reactContext: ReactApplicationContext, key: String, value: String) {
53
+ val prefs = reactContext.getSharedPreferences("gt_store", Context.MODE_PRIVATE)
54
+ prefs.edit().putString(key, value).apply()
67
55
  }
68
- }
56
+ }
@@ -0,0 +1,31 @@
1
+ package com.gtreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.WritableArray
5
+ import com.facebook.react.module.annotations.ReactModule
6
+ import com.facebook.fbreact.specs.NativeGtReactNativeSpec
7
+
8
+ @ReactModule(name = GtReactNativeModuleImpl.NAME)
9
+ class GtReactNativeModule(reactContext: ReactApplicationContext) :
10
+ NativeGtReactNativeSpec(reactContext) {
11
+
12
+ override fun getName(): String {
13
+ return GtReactNativeModuleImpl.NAME
14
+ }
15
+
16
+ override fun multiply(a: Double, b: Double): Double {
17
+ return GtReactNativeModuleImpl.multiply(a, b)
18
+ }
19
+
20
+ override fun getNativeLocales(): WritableArray {
21
+ return GtReactNativeModuleImpl.getNativeLocales(reactApplicationContext)
22
+ }
23
+
24
+ override fun nativeStoreGet(key: String): String? {
25
+ return GtReactNativeModuleImpl.nativeStoreGet(reactApplicationContext, key)
26
+ }
27
+
28
+ override fun nativeStoreSet(key: String, value: String) {
29
+ GtReactNativeModuleImpl.nativeStoreSet(reactApplicationContext, key, value)
30
+ }
31
+ }
@@ -0,0 +1,36 @@
1
+ package com.gtreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+ import com.facebook.react.bridge.WritableArray
7
+ import com.facebook.react.module.annotations.ReactModule
8
+
9
+ @ReactModule(name = GtReactNativeModuleImpl.NAME)
10
+ class GtReactNativeModule(reactContext: ReactApplicationContext) :
11
+ ReactContextBaseJavaModule(reactContext) {
12
+
13
+ override fun getName(): String {
14
+ return GtReactNativeModuleImpl.NAME
15
+ }
16
+
17
+ @ReactMethod(isBlockingSynchronousMethod = true)
18
+ fun multiply(a: Double, b: Double): Double {
19
+ return GtReactNativeModuleImpl.multiply(a, b)
20
+ }
21
+
22
+ @ReactMethod(isBlockingSynchronousMethod = true)
23
+ fun getNativeLocales(): WritableArray {
24
+ return GtReactNativeModuleImpl.getNativeLocales(reactApplicationContext)
25
+ }
26
+
27
+ @ReactMethod(isBlockingSynchronousMethod = true)
28
+ fun nativeStoreGet(key: String): String? {
29
+ return GtReactNativeModuleImpl.nativeStoreGet(reactApplicationContext, key)
30
+ }
31
+
32
+ @ReactMethod
33
+ fun nativeStoreSet(key: String, value: String) {
34
+ GtReactNativeModuleImpl.nativeStoreSet(reactApplicationContext, key, value)
35
+ }
36
+ }
@@ -1,5 +1,13 @@
1
- #import <GtReactNativeSpec/GtReactNativeSpec.h>
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
2
 
3
+ #import <GtReactNativeSpec/GtReactNativeSpec.h>
3
4
  @interface GtReactNative : NSObject <NativeGtReactNativeSpec>
4
5
 
6
+ #else
7
+
8
+ #import <React/RCTBridgeModule.h>
9
+ @interface GtReactNative : NSObject <RCTBridgeModule>
10
+
11
+ #endif
12
+
5
13
  @end
@@ -4,6 +4,8 @@
4
4
  NSUserDefaults *_defaults;
5
5
  }
6
6
 
7
+ RCT_EXPORT_MODULE();
8
+
7
9
  - (instancetype)init
8
10
  {
9
11
  if ((self = [super init])) {
@@ -11,13 +13,13 @@
11
13
  }
12
14
  return self;
13
15
  }
14
- - (NSNumber *)multiply:(double)a b:(double)b {
15
- NSNumber *result = @(a * b);
16
16
 
17
- return result;
17
+ // Internal implementation methods
18
+ - (NSNumber *)multiplyImpl:(double)a b:(double)b {
19
+ return @(a * b);
18
20
  }
19
21
 
20
- - (NSArray<NSString *> *)getNativeLocales {
22
+ - (NSArray<NSString *> *)getNativeLocalesImpl {
21
23
  NSMutableArray<NSString *> *locales = [[NSMutableArray alloc] init];
22
24
 
23
25
  // Add current locale first
@@ -38,27 +40,60 @@
38
40
  return [locales copy];
39
41
  }
40
42
 
41
- - (nullable NSString *)nativeStoreGet:(NSString *)key
43
+ - (nullable NSString *)nativeStoreGetImpl:(NSString *)key
42
44
  {
43
45
  if (key == nil) { return nil; }
44
46
  return [_defaults stringForKey:key];
45
47
  }
46
48
 
47
- - (void)nativeStoreSet:(NSString *)key value:(NSString *)value
49
+ - (void)nativeStoreSetImpl:(NSString *)key value:(NSString *)value
48
50
  {
49
51
  if (key == nil || value == nil) { return; }
50
52
  [_defaults setObject:value forKey:key];
51
53
  }
52
54
 
53
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
54
- (const facebook::react::ObjCTurboModule::InitParams &)params
55
- {
55
+ #ifdef RCT_NEW_ARCH_ENABLED
56
+
57
+ // New architecture
58
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
56
59
  return std::make_shared<facebook::react::NativeGtReactNativeSpecJSI>(params);
57
60
  }
58
61
 
59
- + (NSString *)moduleName
60
- {
61
- return @"GtReactNative";
62
+ - (NSNumber *)multiply:(double)a b:(double)b {
63
+ return [self multiplyImpl:a b:b];
64
+ }
65
+
66
+ - (NSArray<NSString *> *)getNativeLocales {
67
+ return [self getNativeLocalesImpl];
68
+ }
69
+
70
+ - (NSString *)nativeStoreGet:(NSString *)key {
71
+ return [self nativeStoreGetImpl:key];
62
72
  }
63
73
 
74
+ - (void)nativeStoreSet:(NSString *)key value:(NSString *)value {
75
+ [self nativeStoreSetImpl:key value:value];
76
+ }
77
+
78
+ #else
79
+
80
+ // Old architecture
81
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(multiply:(double)a b:(double)b) {
82
+ return [self multiplyImpl:a b:b];
83
+ }
84
+
85
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getNativeLocales) {
86
+ return [self getNativeLocalesImpl];
87
+ }
88
+
89
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(nativeStoreGet:(NSString *)key) {
90
+ return [self nativeStoreGetImpl:key];
91
+ }
92
+
93
+ RCT_EXPORT_METHOD(nativeStoreSet:(NSString *)key value:(NSString *)value) {
94
+ [self nativeStoreSetImpl:key value:value];
95
+ }
96
+
97
+ #endif
98
+
64
99
  @end
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { TurboModuleRegistry } from 'react-native';
4
- export default TurboModuleRegistry.getEnforcing('GtReactNative');
3
+ import { TurboModuleRegistry, NativeModules } from 'react-native';
4
+ // Try TurboModule first, fallback to legacy NativeModule
5
+ export default TurboModuleRegistry.getEnforcing('GtReactNative') ?? NativeModules.GtReactNative;
5
6
  //# sourceMappingURL=NativeGtReactNative.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeGtReactNative.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AASpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","NativeModules","getEnforcing","GtReactNative"],"sourceRoot":"../../src","sources":["NativeGtReactNative.ts"],"mappings":";;AAAA,SAASA,mBAAmB,EAAoBC,aAAa,QAAQ,cAAc;AASnF;AACA,eAAeD,mBAAmB,CAACE,YAAY,CAAO,eAAe,CAAC,IAAID,aAAa,CAACE,aAAa","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"NativeGtReactNative.d.ts","sourceRoot":"","sources":["../../../src/NativeGtReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC,gBAAgB,IAAI,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;;AAED,wBAAuE"}
1
+ {"version":3,"file":"NativeGtReactNative.d.ts","sourceRoot":"","sources":["../../../src/NativeGtReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAiB,MAAM,cAAc,CAAC;AAEpF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC,gBAAgB,IAAI,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;;AAGD,wBAAsG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-react-native",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "An i18n package for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -19,7 +19,6 @@
19
19
  "ios",
20
20
  "cpp",
21
21
  "*.podspec",
22
- "react-native.config.js",
23
22
  "!ios/build",
24
23
  "!android/build",
25
24
  "!android/gradle",
@@ -38,8 +37,8 @@
38
37
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
38
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
39
  "prepare": "bob build",
41
- "release": "yarn clean && yarn npm publish --tag latest",
42
- "release:alpha": "yarn clean && npm publish --tag alpha"
40
+ "release": "yarn clean && yarn prepare && npm publish --tag latest",
41
+ "release:alpha": "yarn clean && yarn prepare && npm publish --tag alpha"
43
42
  },
44
43
  "keywords": [
45
44
  "react-native",
@@ -1,4 +1,4 @@
1
- import { TurboModuleRegistry, type TurboModule } from 'react-native';
1
+ import { TurboModuleRegistry, type TurboModule, NativeModules } from 'react-native';
2
2
 
3
3
  export interface Spec extends TurboModule {
4
4
  multiply(a: number, b: number): number;
@@ -7,4 +7,5 @@ export interface Spec extends TurboModule {
7
7
  nativeStoreSet(key: string, value: string): void;
8
8
  }
9
9
 
10
- export default TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');
10
+ // Try TurboModule first, fallback to legacy NativeModule
11
+ export default TurboModuleRegistry.getEnforcing<Spec>('GtReactNative') ?? NativeModules.GtReactNative;