gt-react-native 0.0.0 → 0.0.1-alpha.10

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.
Files changed (76) hide show
  1. package/GtReactNative.podspec +21 -0
  2. package/LICENSE +105 -0
  3. package/README.md +27 -1
  4. package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeGtReactNativeSpec.java +51 -0
  5. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  6. package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec-generated.cpp +50 -0
  7. package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec.h +31 -0
  8. package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI-generated.cpp +51 -0
  9. package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI.h +98 -0
  10. package/android/build.gradle +88 -0
  11. package/android/gradle.properties +5 -0
  12. package/android/src/main/AndroidManifest.xml +2 -0
  13. package/android/src/main/java/com/gtreactnative/GtReactNativeModuleImpl.kt +56 -0
  14. package/android/src/main/java/com/gtreactnative/GtReactNativePackage.kt +35 -0
  15. package/android/src/newarch/com/gtreactnative/GtReactNativeModule.kt +30 -0
  16. package/android/src/oldarch/com/gtreactnative/GtReactNativeModule.kt +36 -0
  17. package/ios/GtReactNative.h +13 -0
  18. package/ios/GtReactNative.mm +99 -0
  19. package/lib/module/NativeGtReactNative.js +5 -0
  20. package/lib/module/NativeGtReactNative.js.map +1 -0
  21. package/lib/module/errors-dir/constants.js +4 -0
  22. package/lib/module/errors-dir/constants.js.map +1 -0
  23. package/lib/module/index.js +11 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/module/package.json +1 -0
  26. package/lib/module/provider/GTProvider.js +19 -0
  27. package/lib/module/provider/GTProvider.js.map +1 -0
  28. package/lib/module/provider/hooks/locale/useDetermineLocale.js +142 -0
  29. package/lib/module/provider/hooks/locale/useDetermineLocale.js.map +1 -0
  30. package/lib/module/provider/hooks/useRegionState.js +43 -0
  31. package/lib/module/provider/hooks/useRegionState.js.map +1 -0
  32. package/lib/module/types/config.js +4 -0
  33. package/lib/module/types/config.js.map +1 -0
  34. package/lib/module/utils/getNativeLocales.js +54 -0
  35. package/lib/module/utils/getNativeLocales.js.map +1 -0
  36. package/lib/module/utils/nativeStore.js +34 -0
  37. package/lib/module/utils/nativeStore.js.map +1 -0
  38. package/lib/module/utils/polyfill.js +33 -0
  39. package/lib/module/utils/polyfill.js.map +1 -0
  40. package/lib/module/utils/utils.js +13 -0
  41. package/lib/module/utils/utils.js.map +1 -0
  42. package/lib/typescript/package.json +1 -0
  43. package/lib/typescript/src/NativeGtReactNative.d.ts +10 -0
  44. package/lib/typescript/src/NativeGtReactNative.d.ts.map +1 -0
  45. package/lib/typescript/src/errors-dir/constants.d.ts +2 -0
  46. package/lib/typescript/src/errors-dir/constants.d.ts.map +1 -0
  47. package/lib/typescript/src/index.d.ts +7 -0
  48. package/lib/typescript/src/index.d.ts.map +1 -0
  49. package/lib/typescript/src/provider/GTProvider.d.ts +4 -0
  50. package/lib/typescript/src/provider/GTProvider.d.ts.map +1 -0
  51. package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
  52. package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
  53. package/lib/typescript/src/provider/hooks/useRegionState.d.ts +3 -0
  54. package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +1 -0
  55. package/lib/typescript/src/types/config.d.ts +30 -0
  56. package/lib/typescript/src/types/config.d.ts.map +1 -0
  57. package/lib/typescript/src/utils/getNativeLocales.d.ts +10 -0
  58. package/lib/typescript/src/utils/getNativeLocales.d.ts.map +1 -0
  59. package/lib/typescript/src/utils/nativeStore.d.ts +16 -0
  60. package/lib/typescript/src/utils/nativeStore.d.ts.map +1 -0
  61. package/lib/typescript/src/utils/polyfill.d.ts +28 -0
  62. package/lib/typescript/src/utils/polyfill.d.ts.map +1 -0
  63. package/lib/typescript/src/utils/utils.d.ts +3 -0
  64. package/lib/typescript/src/utils/utils.d.ts.map +1 -0
  65. package/package.json +152 -7
  66. package/src/NativeGtReactNative.ts +10 -0
  67. package/src/errors-dir/constants.ts +1 -0
  68. package/src/index.tsx +68 -0
  69. package/src/provider/GTProvider.tsx +20 -0
  70. package/src/provider/hooks/locale/useDetermineLocale.ts +194 -0
  71. package/src/provider/hooks/useRegionState.ts +51 -0
  72. package/src/types/config.ts +35 -0
  73. package/src/utils/getNativeLocales.ts +53 -0
  74. package/src/utils/nativeStore.ts +31 -0
  75. package/src/utils/polyfill.ts +36 -0
  76. package/src/utils/utils.ts +12 -0
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "GtReactNative"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/generaltranslation/gt-react-native.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+
20
+ install_modules_dependencies(s)
21
+ end
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2025 General Translation, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,29 @@
1
1
  # gt-react-native
2
2
 
3
- Placeholder while we work on this! :)
3
+ An i18n package for React Native
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install gt-react-native
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { multiply } from 'gt-react-native';
15
+
16
+ // ...
17
+
18
+ const result = multiply(3, 7);
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
24
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
25
+ - [Code of conduct](CODE_OF_CONDUCT.md)
26
+
27
+ ---
28
+
29
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,51 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJavaSpec.js
9
+ *
10
+ * @nolint
11
+ */
12
+
13
+ package com.facebook.fbreact.specs;
14
+
15
+ import com.facebook.proguard.annotations.DoNotStrip;
16
+ import com.facebook.react.bridge.ReactApplicationContext;
17
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
+ import com.facebook.react.bridge.ReactMethod;
19
+ import com.facebook.react.bridge.WritableArray;
20
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule;
21
+ import javax.annotation.Nonnull;
22
+ import javax.annotation.Nullable;
23
+
24
+ public abstract class NativeGtReactNativeSpec extends ReactContextBaseJavaModule implements TurboModule {
25
+ public static final String NAME = "GtReactNative";
26
+
27
+ public NativeGtReactNativeSpec(ReactApplicationContext reactContext) {
28
+ super(reactContext);
29
+ }
30
+
31
+ @Override
32
+ public @Nonnull String getName() {
33
+ return NAME;
34
+ }
35
+
36
+ @ReactMethod(isBlockingSynchronousMethod = true)
37
+ @DoNotStrip
38
+ public abstract double multiply(double a, double b);
39
+
40
+ @ReactMethod(isBlockingSynchronousMethod = true)
41
+ @DoNotStrip
42
+ public abstract WritableArray getNativeLocales();
43
+
44
+ @ReactMethod(isBlockingSynchronousMethod = true)
45
+ @DoNotStrip
46
+ public abstract @Nullable String nativeStoreGet(String key);
47
+
48
+ @ReactMethod
49
+ @DoNotStrip
50
+ public abstract void nativeStoreSet(String key, String value);
51
+ }
@@ -0,0 +1,28 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ cmake_minimum_required(VERSION 3.13)
7
+ set(CMAKE_VERBOSE_MAKEFILE on)
8
+
9
+ file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/GtReactNativeSpec/*.cpp)
10
+
11
+ add_library(
12
+ react_codegen_GtReactNativeSpec
13
+ OBJECT
14
+ ${react_codegen_SRCS}
15
+ )
16
+
17
+ target_include_directories(react_codegen_GtReactNativeSpec PUBLIC . react/renderer/components/GtReactNativeSpec)
18
+
19
+ target_link_libraries(
20
+ react_codegen_GtReactNativeSpec
21
+ fbjni
22
+ jsi
23
+ # We need to link different libraries based on whether we are building rncore or not, that's necessary
24
+ # because we want to break a circular dependency between react_codegen_rncore and reactnative
25
+ reactnative
26
+ )
27
+
28
+ target_compile_reactnative_options(react_codegen_GtReactNativeSpec PRIVATE)
@@ -0,0 +1,50 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniCpp.js
9
+ */
10
+
11
+ #include "GtReactNativeSpec.h"
12
+
13
+ namespace facebook::react {
14
+
15
+ static facebook::jsi::Value __hostFunction_NativeGtReactNativeSpecJSI_multiply(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
16
+ static jmethodID cachedMethodId = nullptr;
17
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, NumberKind, "multiply", "(DD)D", args, count, cachedMethodId);
18
+ }
19
+
20
+ static facebook::jsi::Value __hostFunction_NativeGtReactNativeSpecJSI_getNativeLocales(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
21
+ static jmethodID cachedMethodId = nullptr;
22
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "getNativeLocales", "()Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
23
+ }
24
+
25
+ static facebook::jsi::Value __hostFunction_NativeGtReactNativeSpecJSI_nativeStoreGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
26
+ static jmethodID cachedMethodId = nullptr;
27
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, StringKind, "nativeStoreGet", "(Ljava/lang/String;)Ljava/lang/String;", args, count, cachedMethodId);
28
+ }
29
+
30
+ static facebook::jsi::Value __hostFunction_NativeGtReactNativeSpecJSI_nativeStoreSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
31
+ static jmethodID cachedMethodId = nullptr;
32
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, VoidKind, "nativeStoreSet", "(Ljava/lang/String;Ljava/lang/String;)V", args, count, cachedMethodId);
33
+ }
34
+
35
+ NativeGtReactNativeSpecJSI::NativeGtReactNativeSpecJSI(const JavaTurboModule::InitParams &params)
36
+ : JavaTurboModule(params) {
37
+ methodMap_["multiply"] = MethodMetadata {2, __hostFunction_NativeGtReactNativeSpecJSI_multiply};
38
+ methodMap_["getNativeLocales"] = MethodMetadata {0, __hostFunction_NativeGtReactNativeSpecJSI_getNativeLocales};
39
+ methodMap_["nativeStoreGet"] = MethodMetadata {1, __hostFunction_NativeGtReactNativeSpecJSI_nativeStoreGet};
40
+ methodMap_["nativeStoreSet"] = MethodMetadata {2, __hostFunction_NativeGtReactNativeSpecJSI_nativeStoreSet};
41
+ }
42
+
43
+ std::shared_ptr<TurboModule> GtReactNativeSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
44
+ if (moduleName == "GtReactNative") {
45
+ return std::make_shared<NativeGtReactNativeSpecJSI>(params);
46
+ }
47
+ return nullptr;
48
+ }
49
+
50
+ } // namespace facebook::react
@@ -0,0 +1,31 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <ReactCommon/JavaTurboModule.h>
14
+ #include <ReactCommon/TurboModule.h>
15
+ #include <jsi/jsi.h>
16
+
17
+ namespace facebook::react {
18
+
19
+ /**
20
+ * JNI C++ class for module 'NativeGtReactNative'
21
+ */
22
+ class JSI_EXPORT NativeGtReactNativeSpecJSI : public JavaTurboModule {
23
+ public:
24
+ NativeGtReactNativeSpecJSI(const JavaTurboModule::InitParams &params);
25
+ };
26
+
27
+
28
+ JSI_EXPORT
29
+ std::shared_ptr<TurboModule> GtReactNativeSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
30
+
31
+ } // namespace facebook::react
@@ -0,0 +1,51 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleCpp.js
8
+ */
9
+
10
+ #include "GtReactNativeSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeGtReactNativeCxxSpecJSI_multiply(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ return static_cast<NativeGtReactNativeCxxSpecJSI *>(&turboModule)->multiply(
16
+ rt,
17
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber(),
18
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asNumber()
19
+ );
20
+ }
21
+ static jsi::Value __hostFunction_NativeGtReactNativeCxxSpecJSI_getNativeLocales(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
22
+ return static_cast<NativeGtReactNativeCxxSpecJSI *>(&turboModule)->getNativeLocales(
23
+ rt
24
+ );
25
+ }
26
+ static jsi::Value __hostFunction_NativeGtReactNativeCxxSpecJSI_nativeStoreGet(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
27
+ auto result = static_cast<NativeGtReactNativeCxxSpecJSI *>(&turboModule)->nativeStoreGet(
28
+ rt,
29
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
30
+ );
31
+ return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
32
+ }
33
+ static jsi::Value __hostFunction_NativeGtReactNativeCxxSpecJSI_nativeStoreSet(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
34
+ static_cast<NativeGtReactNativeCxxSpecJSI *>(&turboModule)->nativeStoreSet(
35
+ rt,
36
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
37
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
38
+ );
39
+ return jsi::Value::undefined();
40
+ }
41
+
42
+ NativeGtReactNativeCxxSpecJSI::NativeGtReactNativeCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
43
+ : TurboModule("GtReactNative", jsInvoker) {
44
+ methodMap_["multiply"] = MethodMetadata {2, __hostFunction_NativeGtReactNativeCxxSpecJSI_multiply};
45
+ methodMap_["getNativeLocales"] = MethodMetadata {0, __hostFunction_NativeGtReactNativeCxxSpecJSI_getNativeLocales};
46
+ methodMap_["nativeStoreGet"] = MethodMetadata {1, __hostFunction_NativeGtReactNativeCxxSpecJSI_nativeStoreGet};
47
+ methodMap_["nativeStoreSet"] = MethodMetadata {2, __hostFunction_NativeGtReactNativeCxxSpecJSI_nativeStoreSet};
48
+ }
49
+
50
+
51
+ } // namespace facebook::react
@@ -0,0 +1,98 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ class JSI_EXPORT NativeGtReactNativeCxxSpecJSI : public TurboModule {
19
+ protected:
20
+ NativeGtReactNativeCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
21
+
22
+ public:
23
+ virtual double multiply(jsi::Runtime &rt, double a, double b) = 0;
24
+ virtual jsi::Array getNativeLocales(jsi::Runtime &rt) = 0;
25
+ virtual std::optional<jsi::String> nativeStoreGet(jsi::Runtime &rt, jsi::String key) = 0;
26
+ virtual void nativeStoreSet(jsi::Runtime &rt, jsi::String key, jsi::String value) = 0;
27
+
28
+ };
29
+
30
+ template <typename T>
31
+ class JSI_EXPORT NativeGtReactNativeCxxSpec : public TurboModule {
32
+ public:
33
+ jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
34
+ return delegate_.create(rt, propName);
35
+ }
36
+
37
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
38
+ return delegate_.getPropertyNames(runtime);
39
+ }
40
+
41
+ static constexpr std::string_view kModuleName = "GtReactNative";
42
+
43
+ protected:
44
+ NativeGtReactNativeCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
45
+ : TurboModule(std::string{NativeGtReactNativeCxxSpec::kModuleName}, jsInvoker),
46
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
47
+
48
+
49
+ private:
50
+ class Delegate : public NativeGtReactNativeCxxSpecJSI {
51
+ public:
52
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
53
+ NativeGtReactNativeCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
54
+
55
+ }
56
+
57
+ double multiply(jsi::Runtime &rt, double a, double b) override {
58
+ static_assert(
59
+ bridging::getParameterCount(&T::multiply) == 3,
60
+ "Expected multiply(...) to have 3 parameters");
61
+
62
+ return bridging::callFromJs<double>(
63
+ rt, &T::multiply, jsInvoker_, instance_, std::move(a), std::move(b));
64
+ }
65
+ jsi::Array getNativeLocales(jsi::Runtime &rt) override {
66
+ static_assert(
67
+ bridging::getParameterCount(&T::getNativeLocales) == 1,
68
+ "Expected getNativeLocales(...) to have 1 parameters");
69
+
70
+ return bridging::callFromJs<jsi::Array>(
71
+ rt, &T::getNativeLocales, jsInvoker_, instance_);
72
+ }
73
+ std::optional<jsi::String> nativeStoreGet(jsi::Runtime &rt, jsi::String key) override {
74
+ static_assert(
75
+ bridging::getParameterCount(&T::nativeStoreGet) == 2,
76
+ "Expected nativeStoreGet(...) to have 2 parameters");
77
+
78
+ return bridging::callFromJs<std::optional<jsi::String>>(
79
+ rt, &T::nativeStoreGet, jsInvoker_, instance_, std::move(key));
80
+ }
81
+ void nativeStoreSet(jsi::Runtime &rt, jsi::String key, jsi::String value) override {
82
+ static_assert(
83
+ bridging::getParameterCount(&T::nativeStoreSet) == 3,
84
+ "Expected nativeStoreSet(...) to have 3 parameters");
85
+
86
+ return bridging::callFromJs<void>(
87
+ rt, &T::nativeStoreSet, jsInvoker_, instance_, std::move(key), std::move(value));
88
+ }
89
+
90
+ private:
91
+ friend class NativeGtReactNativeCxxSpec;
92
+ T *instance_;
93
+ };
94
+
95
+ Delegate delegate_;
96
+ };
97
+
98
+ } // namespace facebook::react
@@ -0,0 +1,88 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['GtReactNative_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+ def isNewArchitectureEnabled() {
19
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
20
+ }
21
+
22
+ apply plugin: "com.android.library"
23
+ apply plugin: "kotlin-android"
24
+
25
+ if (isNewArchitectureEnabled()) {
26
+ apply plugin: "com.facebook.react"
27
+ }
28
+
29
+ def getExtOrIntegerDefault(name) {
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["GtReactNative_" + name]).toInteger()
31
+ }
32
+
33
+ android {
34
+ namespace "com.gtreactnative"
35
+
36
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
37
+
38
+ defaultConfig {
39
+ buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
40
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
41
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
42
+ }
43
+
44
+ buildFeatures {
45
+ buildConfig true
46
+ }
47
+
48
+ buildTypes {
49
+ release {
50
+ minifyEnabled false
51
+ }
52
+ }
53
+
54
+ lintOptions {
55
+ disable "GradleCompatible"
56
+ }
57
+
58
+ compileOptions {
59
+ sourceCompatibility JavaVersion.VERSION_1_8
60
+ targetCompatibility JavaVersion.VERSION_1_8
61
+ }
62
+
63
+ sourceSets {
64
+ main {
65
+ java.srcDirs += [
66
+ "generated/java",
67
+ "generated/jni"
68
+ ]
69
+ if (isNewArchitectureEnabled()) {
70
+ java.srcDirs += ["src/newarch"]
71
+ } else {
72
+ java.srcDirs += ["src/oldarch"]
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ repositories {
79
+ mavenCentral()
80
+ google()
81
+ }
82
+
83
+ def kotlin_version = getExtOrDefault("kotlinVersion")
84
+
85
+ dependencies {
86
+ implementation "com.facebook.react:react-android"
87
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
88
+ }
@@ -0,0 +1,5 @@
1
+ GtReactNative_kotlinVersion=2.0.21
2
+ GtReactNative_minSdkVersion=24
3
+ GtReactNative_targetSdkVersion=34
4
+ GtReactNative_compileSdkVersion=35
5
+ GtReactNative_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,56 @@
1
+ package com.gtreactnative
2
+
3
+ import android.content.Context
4
+ import android.os.Build
5
+ import android.os.LocaleList
6
+ import com.facebook.react.bridge.Arguments
7
+ import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.bridge.WritableArray
9
+ import java.util.Locale
10
+
11
+ object GtReactNativeModuleImpl {
12
+ const val NAME = "GtReactNative"
13
+
14
+ fun multiply(a: Double, b: Double): Double {
15
+ return a * b
16
+ }
17
+
18
+ fun getNativeLocales(reactContext: ReactApplicationContext): WritableArray {
19
+ val locales = Arguments.createArray()
20
+ val seenLocales = mutableSetOf<String>()
21
+
22
+ try {
23
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
24
+ // Use LocaleList for API 24+
25
+ val localeList = LocaleList.getDefault()
26
+ for (i in 0 until localeList.size()) {
27
+ val locale = localeList.get(i)
28
+ val localeString = locale.toLanguageTag()
29
+ if (!seenLocales.contains(localeString)) {
30
+ locales.pushString(localeString)
31
+ seenLocales.add(localeString)
32
+ }
33
+ }
34
+ } else {
35
+ // Fallback to single default locale for older Android versions
36
+ val defaultLocale = Locale.getDefault()
37
+ val localeString = defaultLocale.toLanguageTag()
38
+ locales.pushString(localeString)
39
+ }
40
+ } catch (e: Exception) {
41
+ // Return empty array on any error
42
+ }
43
+
44
+ return locales
45
+ }
46
+
47
+ fun nativeStoreGet(reactContext: ReactApplicationContext, key: String): String? {
48
+ val prefs = reactContext.getSharedPreferences("gt_store", Context.MODE_PRIVATE)
49
+ return prefs.getString(key, null)
50
+ }
51
+
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()
55
+ }
56
+ }
@@ -0,0 +1,35 @@
1
+ package com.gtreactnative
2
+
3
+ import com.gtreactnative.GtReactNativeModuleImpl
4
+ import com.facebook.react.TurboReactPackage
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import com.facebook.react.module.model.ReactModuleInfoProvider
9
+ import java.util.HashMap
10
+
11
+ class GtReactNativePackage : TurboReactPackage() {
12
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
13
+ return if (name == GtReactNativeModuleImpl.NAME) {
14
+ GtReactNativeModule(reactContext)
15
+ } else {
16
+ null
17
+ }
18
+ }
19
+
20
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
21
+ return ReactModuleInfoProvider {
22
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
23
+ val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
24
+ moduleInfos[GtReactNativeModuleImpl.NAME] = ReactModuleInfo(
25
+ GtReactNativeModuleImpl.NAME,
26
+ GtReactNativeModuleImpl.NAME,
27
+ false, // canOverrideExistingModule
28
+ false, // needsEagerInit
29
+ false, // isCxxModule
30
+ isTurboModule // isTurboModule
31
+ )
32
+ moduleInfos
33
+ }
34
+ }
35
+ }