-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Android and iOS implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
31002e3
feat: iOS and Android implementation
f76c028
cleanup and todos
6dbb20d
rename method
c58d03c
Fix secondsFromGMT
65946bc
Remove abbreviation
11936eb
Improve example UI
2db21c2
readme
d3d1ecb
Improve readme
f2105e2
remove todo
troZee b72717c
remove react-native-localize
158dfe0
docs: add docs
cee0c52
rn 80.2
c9fdf21
fixes
7ec06f2
update readme
d219cc7
align versions
6127948
Add warning
1704dff
Merge branch 'main' into trocki/init
b9b6d38
Simple copilot nits
6d762bc
fix import after merge
633df9b
docs: update imports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| project(TimezoneHermesFix) | ||
| cmake_minimum_required(VERSION 3.9.0) | ||
|
|
||
| set(PACKAGE_NAME "timezone-hermes-fix") | ||
|
|
||
| # Add your sources | ||
| add_library( | ||
| ${PACKAGE_NAME} | ||
| SHARED | ||
| src/main/cpp/TimezoneHermesFix.cpp | ||
| src/main/cpp/OnLoad.cpp | ||
| ) | ||
|
|
||
| # Configure C++ 17 | ||
| set_target_properties( | ||
| ${PACKAGE_NAME} | ||
| PROPERTIES | ||
| CXX_STANDARD 17 | ||
| CXX_EXTENSIONS OFF | ||
| POSITION_INDEPENDENT_CODE ON | ||
| LINKER_LANGUAGE CXX | ||
| ) | ||
|
|
||
| find_package(fbjni REQUIRED CONFIG) | ||
| find_package(ReactAndroid REQUIRED CONFIG) | ||
| find_package(hermes-engine REQUIRED CONFIG) | ||
| string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1") | ||
|
|
||
| target_link_libraries( | ||
| ${PACKAGE_NAME} | ||
| hermes-engine::libhermes | ||
| ) | ||
|
|
||
| target_include_directories( | ||
| ${PACKAGE_NAME} | ||
| PRIVATE | ||
| "src/main/cpp" | ||
| "${REACT_NATIVE_DIR}/ReactCommon" | ||
| "${REACT_NATIVE_DIR}/ReactCommon/callinvoker" | ||
| "${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule" | ||
| # Add Hermes include directories | ||
| "${REACT_NATIVE_DIR}/ReactCommon/hermes" | ||
| "${REACT_NATIVE_DIR}/third-party/hermes/API" | ||
| ) | ||
|
|
||
| # Link libraries | ||
| if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) | ||
| target_link_libraries( | ||
| ${PACKAGE_NAME} | ||
| ReactAndroid::reactnative | ||
| ) | ||
| else() | ||
| target_link_libraries( | ||
| ${PACKAGE_NAME} | ||
| ReactAndroid::reactnativejni | ||
| ) | ||
| endif() | ||
|
|
||
| target_link_libraries( | ||
| ${PACKAGE_NAME} | ||
| android | ||
| log | ||
| fbjni::fbjni | ||
| ReactAndroid::jsi | ||
| ) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include <jni.h> | ||
| #include <fbjni/fbjni.h> | ||
| #include "TimezoneHermesFix.h" | ||
|
|
||
| using namespace facebook::jni; | ||
|
|
||
| JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
| return initialize(vm, [] { | ||
| TimezoneHermesFix::registerNatives(); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #include "TimezoneHermesFix.h" | ||
| #include <jsi/jsi.h> | ||
| #include <ReactCommon/CallInvokerHolder.h> | ||
| #include <fbjni/fbjni.h> | ||
| #include <hermes/hermes.h> | ||
| #include <android/log.h> | ||
|
|
||
| using namespace facebook; | ||
| using namespace facebook::jni; | ||
| using namespace facebook::react; | ||
| using namespace facebook::hermes; | ||
|
|
||
| #define LOG_TAG "TimezoneHermesFix" | ||
| #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) | ||
| #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) | ||
|
|
||
| void TimezoneHermesFix::registerNatives() { | ||
| registerHybrid({ | ||
| makeNativeMethod("initHybrid", TimezoneHermesFix::initHybrid), | ||
| makeNativeMethod("coSieDzieje", TimezoneHermesFix::coSieDzieje), | ||
| }); | ||
| } | ||
|
|
||
| jni::local_ref<TimezoneHermesFix::jhybriddata> TimezoneHermesFix::initHybrid( | ||
| jni::alias_ref<jhybridobject>) { | ||
| return makeCxxInstance(); | ||
| } | ||
|
|
||
| void TimezoneHermesFix::coSieDzieje(jlong jsRuntimePtr) { | ||
| LOGD("coSieDzieje called with jsRuntimePtr: %ld", jsRuntimePtr); | ||
|
|
||
| // Get JSI Runtime pointer (equivalent to iOS cxxBridge.runtime) | ||
| auto jsiRuntime = reinterpret_cast<jsi::Runtime*>(jsRuntimePtr); | ||
| if (jsiRuntime == nullptr) { | ||
| LOGE("jsiRuntime is null"); | ||
| return; | ||
| } | ||
|
|
||
| // Cast to HermesRuntime (equivalent to iOS reinterpret_cast) | ||
| auto hermesRuntime = reinterpret_cast<HermesRuntime*>(jsiRuntime); | ||
| if (hermesRuntime == nullptr) { | ||
| LOGE("hermesRuntime is null - not running on Hermes"); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| // Call resetTimezoneCache on Hermes runtime (same as iOS) | ||
| hermesRuntime->resetTimezoneCache(); | ||
| LOGD("Successfully called resetTimezoneCache on Hermes runtime"); | ||
|
|
||
| } catch (const jsi::JSError& error) { | ||
| LOGE("JSI Error calling resetTimezoneCache: %s", error.getMessage().c_str()); | ||
| } catch (const std::exception& error) { | ||
| LOGE("Exception calling resetTimezoneCache: %s", error.what()); | ||
| } | ||
| } | ||
|
|
||
| //void TimezoneHermesFix::resetHermesTimezoneCacheNative( | ||
| // JNIEnv* env, | ||
| // jclass clazz, | ||
| // jlong jsRuntimePtr, | ||
| // jobject callInvokerHolder | ||
| //) { | ||
| // LOGD("resetHermesTimezoneCacheNative called with jsRuntimePtr: %ld", jsRuntimePtr); | ||
| // | ||
| // // Get JSI Runtime pointer (equivalent to iOS cxxBridge.runtime) | ||
| // auto jsiRuntime = reinterpret_cast<jsi::Runtime*>(jsRuntimePtr); | ||
| // if (jsiRuntime == nullptr) { | ||
| // LOGE("jsiRuntime is null"); | ||
| // return; | ||
| // } | ||
| // | ||
| // // Cast to HermesRuntime (equivalent to iOS reinterpret_cast) | ||
| //// auto hermesRuntime = reinterpret_cast<HermesRuntime*>(jsiRuntime); | ||
| //// if (hermesRuntime == nullptr) { | ||
| //// LOGE("hermesRuntime is null - not running on Hermes"); | ||
| //// return; | ||
| //// } | ||
| // | ||
| // try { | ||
| // // Call resetTimezoneCache on Hermes runtime (same as iOS) | ||
| //// hermesRuntime->resetTimezoneCache(); | ||
| // LOGD("Successfully called resetTimezoneCache on Hermes runtime"); | ||
| // | ||
| // } catch (const jsi::JSError& error) { | ||
| // LOGE("JSI Error calling resetTimezoneCache: %s", error.getMessage().c_str()); | ||
| // } catch (const std::exception& error) { | ||
| // LOGE("Exception calling resetTimezoneCache: %s", error.what()); | ||
| // } | ||
| //} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #pragma once | ||
|
|
||
| #include <jni.h> | ||
| #include <jsi/jsi.h> | ||
| #include <ReactCommon/CallInvokerHolder.h> | ||
| #include <fbjni/fbjni.h> | ||
|
|
||
| using namespace facebook; | ||
|
|
||
| class TimezoneHermesFix: public jni::HybridClass<TimezoneHermesFix> { | ||
| public: | ||
| static constexpr auto kJavaDescriptor = "Lcom/timezonehermesfix/TimezoneHermesFixModule;"; | ||
| static void registerNatives(); | ||
| static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>); | ||
|
|
||
| void coSieDzieje(jlong jsRuntimePtr); | ||
troZee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| friend HybridBase; | ||
| TimezoneHermesFix() {} | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.