Skip to content

Commit

Permalink
fix: crash on android reload
Browse files Browse the repository at this point in the history
  • Loading branch information
jpudysz committed Jan 29, 2025
1 parent 79baf09 commit 7b1e446
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion android/src/main/cxx/NativeUnistylesModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jni::local_ref<BindingsInstallerHolder::javaobject> UnistylesModule::getBindings
auto& uiManager = jobj->cthis()->_uiManager;
auto& nativePlatform = jobj->cthis()->_nativePlatform;

return BindingsInstallerHolder::newObjectCxxArgs([&runtimeExecutor, uiManager, nativePlatform](jsi::Runtime& rt) {
return BindingsInstallerHolder::newObjectCxxArgs([&runtimeExecutor, &uiManager, &nativePlatform](jsi::Runtime& rt) {
// function is called on: first init and every live reload
// check if this is live reload, if so let's replace UnistylesRuntime with new runtime
auto hasUnistylesRuntime = HybridObjectRegistry::hasHybridObject("UnistylesRuntime");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
reactContext.addLifecycleEventListener(this)
}

fun invalidate() {
fun onDestroy() {
reactContext.removeLifecycleEventListener(this)
_listener.invalidate()
}

override fun onHostResume() {
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/unistyles/NativePlatform+insets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class NativePlatformInsets(
private val _imeListeners: MutableList<CxxImeListener> = mutableListOf()
private var _insets: Insets = Insets(0.0, 0.0, 0.0, 0.0, 0.0)

fun onDestroy() {
this.removeImeListeners()
}

fun getInsets(): Insets {
val density = reactContext.resources.displayMetrics.density

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class NativePlatformListener(
reactContext.registerReceiver(configurationChangeReceiver, IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED))
}

fun invalidate() {
fun onDestroy() {
this.removePlatformListeners()
reactContext.unregisterReceiver(configurationChangeReceiver)
}

Expand Down
4 changes: 0 additions & 4 deletions android/src/main/java/com/unistyles/UnistylesModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class UnistylesModule(reactContext: ReactApplicationContext): NativeTurboUnistyl
mHybridData = initializeHybridData(reactContext)
}

override fun invalidate() {
_nativePlatform.invalidate()
}

private fun initializeHybridData(reactContext: ReactApplicationContext): HybridData {
val runtimeExecutor = reactContext.catalystInstance?.runtimeExecutor
?: throw IllegalStateException("Unistyles: React Native runtime executor is not available. Please follow installation guides.")
Expand Down

0 comments on commit 7b1e446

Please sign in to comment.