Skip to content
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

Fix timers in headless tasks on bridgeless mode #47496

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public open class JavaTimerManager(

init {
reactApplicationContext.addLifecycleEventListener(this)
HeadlessJsTaskContext.getInstance(reactApplicationContext)
.addTaskEventListener(this)
}

override fun onHostPause() {
Expand Down Expand Up @@ -103,6 +105,8 @@ public open class JavaTimerManager(
}

public open fun onInstanceDestroy() {
HeadlessJsTaskContext.getInstance(reactApplicationContext)
.removeTaskEventListener(this)
reactApplicationContext.removeLifecycleEventListener(this)
clearFrameCallback()
clearChoreographerIdleCallback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableArray
import com.facebook.react.common.annotations.VisibleForTesting
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.jstasks.HeadlessJsTaskContext
import com.facebook.react.module.annotations.ReactModule

/** Native module for JS timer execution. Timers fire on frame boundaries. */
Expand All @@ -24,11 +23,6 @@ public class TimingModule(
private val javaTimerManager: JavaTimerManager =
JavaTimerManager(reactContext, this, ReactChoreographer.getInstance(), devSupportManager)

override fun initialize() {
HeadlessJsTaskContext.getInstance(getReactApplicationContext())
.addTaskEventListener(javaTimerManager)
}

override fun createTimer(
callbackIDDouble: Double,
durationDouble: Double,
Expand Down Expand Up @@ -68,8 +62,6 @@ public class TimingModule(
}

override fun invalidate() {
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext())
headlessJsTaskContext.removeTaskEventListener(javaTimerManager)
javaTimerManager.onInstanceDestroy()
}

Expand Down
Loading