gt-react-native 0.0.1-alpha.3 → 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.
- package/android/build.gradle +12 -1
- package/android/src/main/java/com/gtreactnative/{GtReactNativeModule.kt → GtReactNativeModuleImpl.kt} +11 -24
- package/android/src/newarch/com/gtreactnative/GtReactNativeModule.kt +31 -0
- package/android/src/oldarch/com/gtreactnative/GtReactNativeModule.kt +36 -0
- package/ios/GtReactNative.h +9 -1
- package/ios/GtReactNative.mm +47 -12
- package/lib/module/NativeGtReactNative.js +3 -2
- package/lib/module/NativeGtReactNative.js.map +1 -1
- package/lib/typescript/src/NativeGtReactNative.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/NativeGtReactNative.ts +3 -2
package/android/build.gradle
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
NativeGtReactNativeSpec(reactContext) {
|
|
11
|
+
object GtReactNativeModuleImpl {
|
|
12
|
+
const val NAME = "GtReactNative"
|
|
16
13
|
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|
package/ios/GtReactNative.h
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
#
|
|
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
|
package/ios/GtReactNative.mm
CHANGED
|
@@ -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
|
-
|
|
17
|
+
// Internal implementation methods
|
|
18
|
+
- (NSNumber *)multiplyImpl:(double)a b:(double)b {
|
|
19
|
+
return @(a * b);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
- (NSArray<NSString *> *)
|
|
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 *)
|
|
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)
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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.
|
|
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",
|
|
@@ -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
|
-
|
|
10
|
+
// Try TurboModule first, fallback to legacy NativeModule
|
|
11
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('GtReactNative') ?? NativeModules.GtReactNative;
|