gt-react-native 0.0.0 → 0.0.1-alpha.2
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/GtReactNative.podspec +21 -0
- package/LICENSE +105 -0
- package/README.md +27 -1
- package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeGtReactNativeSpec.java +51 -0
- package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
- package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec-generated.cpp +50 -0
- package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec.h +31 -0
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI-generated.cpp +51 -0
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI.h +98 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativeModule.kt +68 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativePackage.kt +33 -0
- package/ios/GtReactNative.h +5 -0
- package/ios/GtReactNative.mm +64 -0
- package/lib/module/NativeGtReactNative.js +5 -0
- package/lib/module/NativeGtReactNative.js.map +1 -0
- package/lib/module/errors-dir/constants.js +4 -0
- package/lib/module/errors-dir/constants.js.map +1 -0
- package/lib/module/index.js +11 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/provider/GTProvider.js +19 -0
- package/lib/module/provider/GTProvider.js.map +1 -0
- package/lib/module/provider/hooks/locale/useDetermineLocale.js +140 -0
- package/lib/module/provider/hooks/locale/useDetermineLocale.js.map +1 -0
- package/lib/module/provider/hooks/useRegionState.js +55 -0
- package/lib/module/provider/hooks/useRegionState.js.map +1 -0
- package/lib/module/types/config.js +4 -0
- package/lib/module/types/config.js.map +1 -0
- package/lib/module/utils/constants.js +8 -0
- package/lib/module/utils/constants.js.map +1 -0
- package/lib/module/utils/getNativeLocales.js +54 -0
- package/lib/module/utils/getNativeLocales.js.map +1 -0
- package/lib/module/utils/nativeStore.js +34 -0
- package/lib/module/utils/nativeStore.js.map +1 -0
- package/lib/module/utils/polyfill.js +32 -0
- package/lib/module/utils/polyfill.js.map +1 -0
- package/lib/module/utils/utils.js +16 -0
- package/lib/module/utils/utils.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeGtReactNative.d.ts +10 -0
- package/lib/typescript/src/NativeGtReactNative.d.ts.map +1 -0
- package/lib/typescript/src/errors-dir/constants.d.ts +2 -0
- package/lib/typescript/src/errors-dir/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/provider/GTProvider.d.ts +4 -0
- package/lib/typescript/src/provider/GTProvider.d.ts.map +1 -0
- package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
- package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
- package/lib/typescript/src/provider/hooks/useRegionState.d.ts +3 -0
- package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +1 -0
- package/lib/typescript/src/types/config.d.ts +30 -0
- package/lib/typescript/src/types/config.d.ts.map +1 -0
- package/lib/typescript/src/utils/constants.d.ts +3 -0
- package/lib/typescript/src/utils/constants.d.ts.map +1 -0
- package/lib/typescript/src/utils/getNativeLocales.d.ts +10 -0
- package/lib/typescript/src/utils/getNativeLocales.d.ts.map +1 -0
- package/lib/typescript/src/utils/nativeStore.d.ts +16 -0
- package/lib/typescript/src/utils/nativeStore.d.ts.map +1 -0
- package/lib/typescript/src/utils/polyfill.d.ts +28 -0
- package/lib/typescript/src/utils/polyfill.d.ts.map +1 -0
- package/lib/typescript/src/utils/utils.d.ts +3 -0
- package/lib/typescript/src/utils/utils.d.ts.map +1 -0
- package/package.json +153 -7
- package/src/NativeGtReactNative.ts +10 -0
- package/src/errors-dir/constants.ts +1 -0
- package/src/index.tsx +68 -0
- package/src/provider/GTProvider.tsx +20 -0
- package/src/provider/hooks/locale/useDetermineLocale.ts +192 -0
- package/src/provider/hooks/useRegionState.ts +63 -0
- package/src/types/config.ts +35 -0
- package/src/utils/constants.ts +5 -0
- package/src/utils/getNativeLocales.ts +53 -0
- package/src/utils/nativeStore.ts +31 -0
- package/src/utils/polyfill.ts +36 -0
- package/src/utils/utils.ts +13 -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
|
-
|
|
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 ¶ms)
|
|
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 ¶ms) {
|
|
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 ¶ms);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
JSI_EXPORT
|
|
29
|
+
std::shared_ptr<TurboModule> GtReactNativeSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
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,77 @@
|
|
|
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
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["GtReactNative_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.gtreactnative"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import java.util.Locale
|
|
11
|
+
|
|
12
|
+
@ReactModule(name = GtReactNativeModule.NAME)
|
|
13
|
+
class GtReactNativeModule(reactContext: ReactApplicationContext) :
|
|
14
|
+
NativeGtReactNativeSpec(reactContext) {
|
|
15
|
+
|
|
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 {
|
|
27
|
+
return a * b
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getNativeLocales(): WritableArray {
|
|
31
|
+
val locales = Arguments.createArray()
|
|
32
|
+
val seenLocales = mutableSetOf<String>()
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
36
|
+
// Use LocaleList for API 24+
|
|
37
|
+
val localeList = LocaleList.getDefault()
|
|
38
|
+
for (i in 0 until localeList.size()) {
|
|
39
|
+
val locale = localeList.get(i)
|
|
40
|
+
val localeString = locale.toLanguageTag()
|
|
41
|
+
if (!seenLocales.contains(localeString)) {
|
|
42
|
+
locales.pushString(localeString)
|
|
43
|
+
seenLocales.add(localeString)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
// Fallback to single default locale for older Android versions
|
|
48
|
+
val defaultLocale = Locale.getDefault()
|
|
49
|
+
val localeString = defaultLocale.toLanguageTag()
|
|
50
|
+
locales.pushString(localeString)
|
|
51
|
+
}
|
|
52
|
+
} catch (e: Exception) {
|
|
53
|
+
// Return empty array on any error
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return locales
|
|
57
|
+
}
|
|
58
|
+
|
|
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()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
companion object {
|
|
66
|
+
const val NAME = "GtReactNative"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.gtreactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class GtReactNativePackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == GtReactNativeModule.NAME) {
|
|
13
|
+
GtReactNativeModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[GtReactNativeModule.NAME] = ReactModuleInfo(
|
|
23
|
+
GtReactNativeModule.NAME,
|
|
24
|
+
GtReactNativeModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|