gt-react-native 0.0.1-alpha.3 → 0.0.1-alpha.6

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,29 +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
- import com.facebook.fbreact.specs.NativeGtReactNativeSpec
11
9
  import java.util.Locale
12
10
 
13
- @ReactModule(name = GtReactNativeModule.NAME)
14
- class GtReactNativeModule(reactContext: ReactApplicationContext) :
15
- NativeGtReactNativeSpec(reactContext) {
11
+ object GtReactNativeModuleImpl {
12
+ const val NAME = "GtReactNative"
16
13
 
17
- private val prefs by lazy {
18
- reactApplicationContext.getSharedPreferences("gt_store", Context.MODE_PRIVATE)
19
- }
20
-
21
- override fun getName(): String {
22
- return NAME
23
- }
24
-
25
- // Example method
26
- // See https://reactnative.dev/docs/native-modules-android
27
- override fun multiply(a: Double, b: Double): Double {
14
+ fun multiply(a: Double, b: Double): Double {
28
15
  return a * b
29
16
  }
30
17
 
31
- override fun getNativeLocales(): WritableArray {
18
+ fun getNativeLocales(reactContext: ReactApplicationContext): WritableArray {
32
19
  val locales = Arguments.createArray()
33
20
  val seenLocales = mutableSetOf<String>()
34
21
 
@@ -57,13 +44,13 @@ class GtReactNativeModule(reactContext: ReactApplicationContext) :
57
44
  return locales
58
45
  }
59
46
 
60
- override fun nativeStoreGet(key: String): String? = prefs.getString(key, null)
61
-
62
- override fun nativeStoreSet(key: String, value: String) {
63
- 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)
64
50
  }
65
51
 
66
- companion object {
67
- 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()
68
55
  }
69
- }
56
+ }
@@ -1,13 +1,13 @@
1
1
  package com.gtreactnative
2
2
 
3
- import com.facebook.react.BaseReactPackage
3
+ import com.facebook.react.TurboReactPackage
4
4
  import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.module.model.ReactModuleInfo
7
7
  import com.facebook.react.module.model.ReactModuleInfoProvider
8
8
  import java.util.HashMap
9
9
 
10
- class GtReactNativePackage : BaseReactPackage() {
10
+ class GtReactNativePackage : TurboReactPackage() {
11
11
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
12
  return if (name == GtReactNativeModule.NAME) {
13
13
  GtReactNativeModule(reactContext)
@@ -19,13 +19,14 @@ class GtReactNativePackage : BaseReactPackage() {
19
19
  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
20
  return ReactModuleInfoProvider {
21
21
  val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
22
23
  moduleInfos[GtReactNativeModule.NAME] = ReactModuleInfo(
23
24
  GtReactNativeModule.NAME,
24
25
  GtReactNativeModule.NAME,
25
26
  false, // canOverrideExistingModule
26
27
  false, // needsEagerInit
27
28
  false, // isCxxModule
28
- true // isTurboModule
29
+ isTurboModule // isTurboModule
29
30
  )
30
31
  moduleInfos
31
32
  }
@@ -0,0 +1,30 @@
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
+
7
+ @ReactModule(name = GtReactNativeModuleImpl.NAME)
8
+ class GtReactNativeModule(reactContext: ReactApplicationContext) :
9
+ NativeGtReactNativeSpec(reactContext) {
10
+
11
+ override fun getName(): String {
12
+ return GtReactNativeModuleImpl.NAME
13
+ }
14
+
15
+ override fun multiply(a: Double, b: Double): Double {
16
+ return GtReactNativeModuleImpl.multiply(a, b)
17
+ }
18
+
19
+ override fun getNativeLocales(): WritableArray {
20
+ return GtReactNativeModuleImpl.getNativeLocales(reactApplicationContext)
21
+ }
22
+
23
+ override fun nativeStoreGet(key: String): String? {
24
+ return GtReactNativeModuleImpl.nativeStoreGet(reactApplicationContext, key)
25
+ }
26
+
27
+ override fun nativeStoreSet(key: String, value: String) {
28
+ GtReactNativeModuleImpl.nativeStoreSet(reactApplicationContext, key, value)
29
+ }
30
+ }
@@ -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
+ t
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 +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","getEnforcing"],"sourceRoot":"../../src","sources":["NativeGtReactNative.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAQlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { type TurboModule } from 'react-native';
1
+ import type { TurboModule } from 'react-native';
2
2
  export interface Spec extends TurboModule {
3
3
  multiply(a: number, b: number): number;
4
4
  getNativeLocales(): string[];
@@ -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,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-react-native",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.6",
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",
@@ -1,5 +1,5 @@
1
- import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
-
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
3
  export interface Spec extends TurboModule {
4
4
  multiply(a: number, b: number): number;
5
5
  getNativeLocales(): string[];