react-native-timezone 3.0.1 → 3.1.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/android/build.gradle +19 -9
- package/android/generated/java/com/samitha/timezone/NativeTimezoneSpec.java +50 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNTimezoneSpec-generated.cpp +50 -0
- package/android/generated/jni/RNTimezoneSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNTimezoneSpec/RNTimezoneSpecJSI-generated.cpp +48 -0
- package/android/generated/jni/react/renderer/components/RNTimezoneSpec/RNTimezoneSpecJSI.h +94 -0
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/samitha/timezone/TimezoneModule.kt +86 -0
- package/android/src/main/java/com/samitha/timezone/TimezonePackage.kt +34 -0
- package/ios/Timezone.h +1 -7
- package/ios/Timezone.mm +38 -33
- package/ios/generated/RNTimezoneSpec/RNTimezoneSpec-generated.mm +60 -0
- package/ios/generated/RNTimezoneSpec/RNTimezoneSpec.h +62 -0
- package/ios/generated/RNTimezoneSpecJSI-generated.cpp +48 -0
- package/ios/generated/RNTimezoneSpecJSI.h +94 -0
- package/lib/commonjs/NativeTimezone.js.map +1 -1
- package/lib/commonjs/index.js +7 -18
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeTimezone.js +2 -0
- package/lib/module/NativeTimezone.js.map +1 -1
- package/lib/module/index.js +5 -15
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeTimezone.d.ts +10 -0
- package/lib/typescript/commonjs/src/NativeTimezone.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +8 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeTimezone.d.ts +10 -0
- package/lib/typescript/module/src/NativeTimezone.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +8 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +67 -38
- package/react-native-timezone.podspec +19 -21
- package/react-native.config.js +12 -0
- package/src/NativeTimezone.ts +4 -3
- package/src/index.tsx +4 -25
- package/android/src/main/java/com/samitha/rn/timezone/TimezoneModuleImpl.java +0 -60
- package/android/src/main/java/com/samitha/rn/timezone/TimezonePackage.java +0 -45
- package/android/src/newarch/TimezoneModule.java +0 -9
- package/android/src/oldarch/TimezoneModule.java +0 -39
- package/lib/commonjs/index.d.js +0 -6
- package/lib/commonjs/index.d.js.map +0 -1
- package/lib/module/index.d.js +0 -2
- package/lib/module/index.d.js.map +0 -1
- package/lib/typescript/src/NativeTimezone.d.ts +0 -9
- package/lib/typescript/src/NativeTimezone.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -8
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/src/index.d.ts +0 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Samitha Nanayakkara
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@ Timezone version 3.0.0 only supports React Native version 0.62.3 and above due t
|
|
|
16
16
|
|
|
17
17
|
| React native version | Tested | Result |
|
|
18
18
|
| -------------------- | ------ | ------ |
|
|
19
|
-
| 0.62.3 + | ✅ | ✅ |
|
|
20
19
|
| 0.70.0 + | ✅ | ✅ |
|
|
21
20
|
| 0.73.0 + | ✅ | ✅ |
|
|
21
|
+
| 0.76.5 + | ✅ | ✅ |
|
|
22
22
|
|
|
23
23
|
# Installation
|
|
24
24
|
|
package/android/build.gradle
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Timezone_kotlinVersion"]
|
|
4
|
+
|
|
2
5
|
repositories {
|
|
3
6
|
google()
|
|
4
7
|
mavenCentral()
|
|
@@ -6,14 +9,22 @@ buildscript {
|
|
|
6
9
|
|
|
7
10
|
dependencies {
|
|
8
11
|
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
|
|
17
|
+
def reactNativeArchitectures() {
|
|
18
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
19
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
def isNewArchitectureEnabled() {
|
|
13
23
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
apply plugin: "com.android.library"
|
|
27
|
+
apply plugin: "kotlin-android"
|
|
17
28
|
|
|
18
29
|
if (isNewArchitectureEnabled()) {
|
|
19
30
|
apply plugin: "com.facebook.react"
|
|
@@ -38,7 +49,7 @@ def supportsNamespace() {
|
|
|
38
49
|
|
|
39
50
|
android {
|
|
40
51
|
if (supportsNamespace()) {
|
|
41
|
-
namespace "com.samitha.
|
|
52
|
+
namespace "com.samitha.timezone"
|
|
42
53
|
|
|
43
54
|
sourceSets {
|
|
44
55
|
main {
|
|
@@ -78,13 +89,10 @@ android {
|
|
|
78
89
|
sourceSets {
|
|
79
90
|
main {
|
|
80
91
|
if (isNewArchitectureEnabled()) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]
|
|
86
|
-
} else {
|
|
87
|
-
java.srcDirs += ["src/oldarch"]
|
|
92
|
+
java.srcDirs += [
|
|
93
|
+
"generated/java",
|
|
94
|
+
"generated/jni"
|
|
95
|
+
]
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -95,18 +103,20 @@ repositories {
|
|
|
95
103
|
google()
|
|
96
104
|
}
|
|
97
105
|
|
|
106
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
98
107
|
|
|
99
108
|
dependencies {
|
|
100
109
|
// For < 0.71, this will be from the local maven repo
|
|
101
110
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
102
111
|
//noinspection GradleDynamicVersion
|
|
103
112
|
implementation "com.facebook.react:react-native:+"
|
|
113
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
if (isNewArchitectureEnabled()) {
|
|
107
117
|
react {
|
|
108
118
|
jsRootDir = file("../src/")
|
|
109
119
|
libraryName = "Timezone"
|
|
110
|
-
codegenJavaPackageName = "com.samitha.
|
|
120
|
+
codegenJavaPackageName = "com.samitha.timezone"
|
|
111
121
|
}
|
|
112
122
|
}
|
|
@@ -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: GenerateModuleJavaSpec.js
|
|
9
|
+
*
|
|
10
|
+
* @nolint
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
package com.samitha.timezone;
|
|
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.turbomodule.core.interfaces.TurboModule;
|
|
20
|
+
import javax.annotation.Nonnull;
|
|
21
|
+
import javax.annotation.Nullable;
|
|
22
|
+
|
|
23
|
+
public abstract class NativeTimezoneSpec extends ReactContextBaseJavaModule implements TurboModule {
|
|
24
|
+
public static final String NAME = "Timezone";
|
|
25
|
+
|
|
26
|
+
public NativeTimezoneSpec(ReactApplicationContext reactContext) {
|
|
27
|
+
super(reactContext);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Override
|
|
31
|
+
public @Nonnull String getName() {
|
|
32
|
+
return NAME;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
public abstract @Nullable String getTimeZone();
|
|
38
|
+
|
|
39
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
40
|
+
@DoNotStrip
|
|
41
|
+
public abstract @Nullable String getRegionByLocale();
|
|
42
|
+
|
|
43
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
44
|
+
@DoNotStrip
|
|
45
|
+
public abstract @Nullable String getRegionByTelephony();
|
|
46
|
+
|
|
47
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
48
|
+
@DoNotStrip
|
|
49
|
+
public abstract @Nullable Boolean isAutoTimeZoneEnabled();
|
|
50
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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/RNTimezoneSpec/*.cpp)
|
|
10
|
+
|
|
11
|
+
add_library(
|
|
12
|
+
react_codegen_RNTimezoneSpec
|
|
13
|
+
OBJECT
|
|
14
|
+
${react_codegen_SRCS}
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
target_include_directories(react_codegen_RNTimezoneSpec PUBLIC . react/renderer/components/RNTimezoneSpec)
|
|
18
|
+
|
|
19
|
+
target_link_libraries(
|
|
20
|
+
react_codegen_RNTimezoneSpec
|
|
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_options(
|
|
29
|
+
react_codegen_RNTimezoneSpec
|
|
30
|
+
PRIVATE
|
|
31
|
+
-DLOG_TAG=\"ReactNative\"
|
|
32
|
+
-fexceptions
|
|
33
|
+
-frtti
|
|
34
|
+
-std=c++20
|
|
35
|
+
-Wall
|
|
36
|
+
)
|
|
@@ -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 "RNTimezoneSpec.h"
|
|
12
|
+
|
|
13
|
+
namespace facebook::react {
|
|
14
|
+
|
|
15
|
+
static facebook::jsi::Value __hostFunction_NativeTimezoneSpecJSI_getTimeZone(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, StringKind, "getTimeZone", "()Ljava/lang/String;", args, count, cachedMethodId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static facebook::jsi::Value __hostFunction_NativeTimezoneSpecJSI_getRegionByLocale(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, StringKind, "getRegionByLocale", "()Ljava/lang/String;", args, count, cachedMethodId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static facebook::jsi::Value __hostFunction_NativeTimezoneSpecJSI_getRegionByTelephony(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, "getRegionByTelephony", "()Ljava/lang/String;", args, count, cachedMethodId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static facebook::jsi::Value __hostFunction_NativeTimezoneSpecJSI_isAutoTimeZoneEnabled(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, BooleanKind, "isAutoTimeZoneEnabled", "()Ljava/lang/Boolean;", args, count, cachedMethodId);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
NativeTimezoneSpecJSI::NativeTimezoneSpecJSI(const JavaTurboModule::InitParams ¶ms)
|
|
36
|
+
: JavaTurboModule(params) {
|
|
37
|
+
methodMap_["getTimeZone"] = MethodMetadata {0, __hostFunction_NativeTimezoneSpecJSI_getTimeZone};
|
|
38
|
+
methodMap_["getRegionByLocale"] = MethodMetadata {0, __hostFunction_NativeTimezoneSpecJSI_getRegionByLocale};
|
|
39
|
+
methodMap_["getRegionByTelephony"] = MethodMetadata {0, __hostFunction_NativeTimezoneSpecJSI_getRegionByTelephony};
|
|
40
|
+
methodMap_["isAutoTimeZoneEnabled"] = MethodMetadata {0, __hostFunction_NativeTimezoneSpecJSI_isAutoTimeZoneEnabled};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
std::shared_ptr<TurboModule> RNTimezoneSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
44
|
+
if (moduleName == "Timezone") {
|
|
45
|
+
return std::make_shared<NativeTimezoneSpecJSI>(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 'NativeTimezone'
|
|
21
|
+
*/
|
|
22
|
+
class JSI_EXPORT NativeTimezoneSpecJSI : public JavaTurboModule {
|
|
23
|
+
public:
|
|
24
|
+
NativeTimezoneSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
JSI_EXPORT
|
|
29
|
+
std::shared_ptr<TurboModule> RNTimezoneSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
30
|
+
|
|
31
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,48 @@
|
|
|
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 "RNTimezoneSpecJSI.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
static jsi::Value __hostFunction_NativeTimezoneCxxSpecJSI_getTimeZone(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
15
|
+
auto result = static_cast<NativeTimezoneCxxSpecJSI *>(&turboModule)->getTimeZone(
|
|
16
|
+
rt
|
|
17
|
+
);
|
|
18
|
+
return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
|
|
19
|
+
}
|
|
20
|
+
static jsi::Value __hostFunction_NativeTimezoneCxxSpecJSI_getRegionByLocale(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
21
|
+
auto result = static_cast<NativeTimezoneCxxSpecJSI *>(&turboModule)->getRegionByLocale(
|
|
22
|
+
rt
|
|
23
|
+
);
|
|
24
|
+
return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
|
|
25
|
+
}
|
|
26
|
+
static jsi::Value __hostFunction_NativeTimezoneCxxSpecJSI_getRegionByTelephony(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
27
|
+
auto result = static_cast<NativeTimezoneCxxSpecJSI *>(&turboModule)->getRegionByTelephony(
|
|
28
|
+
rt
|
|
29
|
+
);
|
|
30
|
+
return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
|
|
31
|
+
}
|
|
32
|
+
static jsi::Value __hostFunction_NativeTimezoneCxxSpecJSI_isAutoTimeZoneEnabled(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
33
|
+
auto result = static_cast<NativeTimezoneCxxSpecJSI *>(&turboModule)->isAutoTimeZoneEnabled(
|
|
34
|
+
rt
|
|
35
|
+
);
|
|
36
|
+
return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
NativeTimezoneCxxSpecJSI::NativeTimezoneCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
40
|
+
: TurboModule("Timezone", jsInvoker) {
|
|
41
|
+
methodMap_["getTimeZone"] = MethodMetadata {0, __hostFunction_NativeTimezoneCxxSpecJSI_getTimeZone};
|
|
42
|
+
methodMap_["getRegionByLocale"] = MethodMetadata {0, __hostFunction_NativeTimezoneCxxSpecJSI_getRegionByLocale};
|
|
43
|
+
methodMap_["getRegionByTelephony"] = MethodMetadata {0, __hostFunction_NativeTimezoneCxxSpecJSI_getRegionByTelephony};
|
|
44
|
+
methodMap_["isAutoTimeZoneEnabled"] = MethodMetadata {0, __hostFunction_NativeTimezoneCxxSpecJSI_isAutoTimeZoneEnabled};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,94 @@
|
|
|
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 NativeTimezoneCxxSpecJSI : public TurboModule {
|
|
19
|
+
protected:
|
|
20
|
+
NativeTimezoneCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
virtual std::optional<jsi::String> getTimeZone(jsi::Runtime &rt) = 0;
|
|
24
|
+
virtual std::optional<jsi::String> getRegionByLocale(jsi::Runtime &rt) = 0;
|
|
25
|
+
virtual std::optional<jsi::String> getRegionByTelephony(jsi::Runtime &rt) = 0;
|
|
26
|
+
virtual std::optional<bool> isAutoTimeZoneEnabled(jsi::Runtime &rt) = 0;
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
template <typename T>
|
|
31
|
+
class JSI_EXPORT NativeTimezoneCxxSpec : public TurboModule {
|
|
32
|
+
public:
|
|
33
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
|
34
|
+
return delegate_.get(rt, propName);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static constexpr std::string_view kModuleName = "Timezone";
|
|
38
|
+
|
|
39
|
+
protected:
|
|
40
|
+
NativeTimezoneCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
|
41
|
+
: TurboModule(std::string{NativeTimezoneCxxSpec::kModuleName}, jsInvoker),
|
|
42
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
class Delegate : public NativeTimezoneCxxSpecJSI {
|
|
47
|
+
public:
|
|
48
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
|
49
|
+
NativeTimezoneCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
std::optional<jsi::String> getTimeZone(jsi::Runtime &rt) override {
|
|
54
|
+
static_assert(
|
|
55
|
+
bridging::getParameterCount(&T::getTimeZone) == 1,
|
|
56
|
+
"Expected getTimeZone(...) to have 1 parameters");
|
|
57
|
+
|
|
58
|
+
return bridging::callFromJs<std::optional<jsi::String>>(
|
|
59
|
+
rt, &T::getTimeZone, jsInvoker_, instance_);
|
|
60
|
+
}
|
|
61
|
+
std::optional<jsi::String> getRegionByLocale(jsi::Runtime &rt) override {
|
|
62
|
+
static_assert(
|
|
63
|
+
bridging::getParameterCount(&T::getRegionByLocale) == 1,
|
|
64
|
+
"Expected getRegionByLocale(...) to have 1 parameters");
|
|
65
|
+
|
|
66
|
+
return bridging::callFromJs<std::optional<jsi::String>>(
|
|
67
|
+
rt, &T::getRegionByLocale, jsInvoker_, instance_);
|
|
68
|
+
}
|
|
69
|
+
std::optional<jsi::String> getRegionByTelephony(jsi::Runtime &rt) override {
|
|
70
|
+
static_assert(
|
|
71
|
+
bridging::getParameterCount(&T::getRegionByTelephony) == 1,
|
|
72
|
+
"Expected getRegionByTelephony(...) to have 1 parameters");
|
|
73
|
+
|
|
74
|
+
return bridging::callFromJs<std::optional<jsi::String>>(
|
|
75
|
+
rt, &T::getRegionByTelephony, jsInvoker_, instance_);
|
|
76
|
+
}
|
|
77
|
+
std::optional<bool> isAutoTimeZoneEnabled(jsi::Runtime &rt) override {
|
|
78
|
+
static_assert(
|
|
79
|
+
bridging::getParameterCount(&T::isAutoTimeZoneEnabled) == 1,
|
|
80
|
+
"Expected isAutoTimeZoneEnabled(...) to have 1 parameters");
|
|
81
|
+
|
|
82
|
+
return bridging::callFromJs<std::optional<bool>>(
|
|
83
|
+
rt, &T::isAutoTimeZoneEnabled, jsInvoker_, instance_);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
friend class NativeTimezoneCxxSpec;
|
|
88
|
+
T *instance_;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
Delegate delegate_;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
package com.samitha.timezone
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver
|
|
4
|
+
import android.os.Build
|
|
5
|
+
import android.provider.Settings
|
|
6
|
+
import android.telephony.TelephonyManager
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import java.util.TimeZone
|
|
11
|
+
|
|
12
|
+
@ReactModule(name = TimezoneModule.NAME)
|
|
13
|
+
class TimezoneModule(reactContext: ReactApplicationContext) :
|
|
14
|
+
NativeTimezoneSpec(reactContext) {
|
|
15
|
+
|
|
16
|
+
override fun getName(): String = NAME
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is a Synchronous method.
|
|
20
|
+
* Checks if the device is set to automatically detect the time zone.
|
|
21
|
+
*/
|
|
22
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
23
|
+
override fun isAutoTimeZoneEnabled(): Boolean? {
|
|
24
|
+
return try {
|
|
25
|
+
val resolver: ContentResolver = reactApplicationContext.contentResolver
|
|
26
|
+
val isLaterThanJelly = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
|
|
27
|
+
if (isLaterThanJelly) {
|
|
28
|
+
Settings.Global.getInt(resolver, Settings.Global.AUTO_TIME_ZONE, 0) != 0
|
|
29
|
+
} else {
|
|
30
|
+
Settings.System.getInt(resolver, Settings.System.AUTO_TIME_ZONE, 0) != 0
|
|
31
|
+
}
|
|
32
|
+
} catch (e: Exception) {
|
|
33
|
+
null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This is a Synchronous method.
|
|
39
|
+
* Retrieves the current time zone ID.
|
|
40
|
+
*/
|
|
41
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
42
|
+
override fun getTimeZone(): String? {
|
|
43
|
+
return try {
|
|
44
|
+
TimeZone.getDefault().id
|
|
45
|
+
} catch (e: Exception) {
|
|
46
|
+
null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Synchronous method.
|
|
52
|
+
* Gets the region based on the telephony manager's network country ISO.
|
|
53
|
+
*/
|
|
54
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
55
|
+
override fun getRegionByTelephony(): String? {
|
|
56
|
+
return try {
|
|
57
|
+
val telephonyService = reactApplicationContext.getSystemService(ReactApplicationContext.TELEPHONY_SERVICE) as? TelephonyManager
|
|
58
|
+
telephonyService?.networkCountryIso
|
|
59
|
+
} catch (e: Exception) {
|
|
60
|
+
null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Synchronous method.
|
|
66
|
+
* Retrieves the region based on the device's locale.
|
|
67
|
+
*/
|
|
68
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
69
|
+
override fun getRegionByLocale(): String? {
|
|
70
|
+
return try {
|
|
71
|
+
val configuration = reactApplicationContext.resources.configuration
|
|
72
|
+
val locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
73
|
+
configuration.locales.get(0)
|
|
74
|
+
} else {
|
|
75
|
+
configuration.locale
|
|
76
|
+
}
|
|
77
|
+
locale.country
|
|
78
|
+
} catch (e: Exception) {
|
|
79
|
+
null
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
companion object {
|
|
84
|
+
const val NAME = "Timezone"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.samitha.timezone
|
|
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 TimezonePackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == TimezoneModule.NAME) {
|
|
13
|
+
TimezoneModule(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[TimezoneModule.NAME] = ReactModuleInfo(
|
|
23
|
+
TimezoneModule.NAME,
|
|
24
|
+
TimezoneModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
true, // hasConstants
|
|
28
|
+
false, // isCxxModule
|
|
29
|
+
true // isTurboModule
|
|
30
|
+
)
|
|
31
|
+
moduleInfos
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/ios/Timezone.h
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
#
|
|
3
|
-
#import "RNTimezoneSpec.h"
|
|
2
|
+
#import "generated/RNTimezoneSpec/RNTimezoneSpec.h"
|
|
4
3
|
|
|
5
4
|
@interface Timezone : NSObject <NativeTimezoneSpec>
|
|
6
|
-
#else
|
|
7
|
-
#import <React/RCTBridgeModule.h>
|
|
8
|
-
|
|
9
|
-
@interface Timezone : NSObject <RCTBridgeModule>
|
|
10
|
-
#endif
|
|
11
5
|
|
|
12
6
|
@end
|
package/ios/Timezone.mm
CHANGED
|
@@ -3,42 +3,47 @@
|
|
|
3
3
|
#import "Timezone.h"
|
|
4
4
|
|
|
5
5
|
@implementation Timezone
|
|
6
|
-
RCT_EXPORT_MODULE()
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
RCT_EXPORT_MODULE('Timezone');
|
|
7
|
+
/**
|
|
8
|
+
* This is a Synchronous method.
|
|
9
|
+
* Retrieves the current time zone name.
|
|
10
|
+
*/
|
|
11
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getTimeZone)
|
|
12
|
+
{
|
|
13
|
+
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
|
|
14
|
+
return timeZone.name;
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Synchronous method.
|
|
19
|
+
* Gets the region based on the telephony manager's network country ISO.
|
|
20
|
+
*/
|
|
21
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRegionByTelephony)
|
|
22
|
+
{
|
|
23
|
+
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
|
|
24
|
+
CTCarrier *carrier = [networkInfo subscriberCellularProvider];
|
|
25
|
+
NSString *isoCountryCode = [carrier isoCountryCode];
|
|
26
|
+
if (isoCountryCode == nil || [isoCountryCode isEqualToString:@""]) {
|
|
27
|
+
return nil;
|
|
28
|
+
}
|
|
29
|
+
return isoCountryCode;
|
|
23
30
|
}
|
|
24
|
-
return isoCountryCode;
|
|
25
|
-
}
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Synchronous method.
|
|
34
|
+
* Retrieves the region based on the device's locale.
|
|
35
|
+
*/
|
|
36
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getRegionByLocale)
|
|
37
|
+
{
|
|
38
|
+
NSLocale *locale = [NSLocale currentLocale];
|
|
39
|
+
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
|
|
40
|
+
return countryCode;
|
|
41
|
+
}
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return std::make_shared<facebook::react::NativeTimezoneSpecJSI>(params);
|
|
41
|
-
}
|
|
42
|
-
#endif
|
|
43
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
44
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
45
|
+
{
|
|
46
|
+
return std::make_shared<facebook::react::NativeTimezoneSpecJSI>(params);
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
@end
|