Skip to content
Merged
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 @@ -44,7 +44,7 @@ class KeyboardControllerPackage : BaseReactPackage() {
ReactModuleInfo(
StatusBarManagerCompatModuleImpl.NAME,
StatusBarManagerCompatModuleImpl.NAME,
false, // canOverrideExistingModule
true, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
isTurboModule, // isTurboModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class StatusBarManagerCompatModule(

override fun getName(): String = StatusBarManagerCompatModuleImpl.NAME

override fun getConstants(): MutableMap<String, Any>? = module.getConstants()

override fun setHidden(hidden: Boolean) {
module.setHidden(hidden)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class KeyboardControllerViewManagerImpl {
view: EdgeToEdgeReactViewGroup,
enabled: Boolean,
) {
view.setActive(enabled)
view.active = enabled
}

fun setStatusBarTranslucent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.modules.statusbar.StatusBarModule
import com.reactnativekeyboardcontroller.extensions.rootView
import com.reactnativekeyboardcontroller.log.Logger
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
Expand All @@ -19,10 +20,15 @@ private val TAG = StatusBarManagerCompatModuleImpl::class.qualifiedName
class StatusBarManagerCompatModuleImpl(
private val mReactContext: ReactApplicationContext,
) {
private var original = StatusBarModule(mReactContext)
private var controller: WindowInsetsControllerCompat? = null
private var lastActivity = WeakReference<Activity?>(null)

fun setHidden(hidden: Boolean) {
if (!isEnabled()) {
return original.setHidden(hidden)
}

UiThreadUtil.runOnUiThread {
if (hidden) {
getController()?.hide(WindowInsetsCompat.Type.statusBars())
Expand All @@ -37,6 +43,10 @@ class StatusBarManagerCompatModuleImpl(
color: Int,
animated: Boolean,
) {
if (!isEnabled()) {
return original.setColor(color.toDouble(), animated)
}

val activity = mReactContext.currentActivity
if (activity == null) {
Logger.w(TAG, "StatusBarManagerCompatModule: Ignored status bar change, current activity is null.")
Expand All @@ -61,18 +71,27 @@ class StatusBarManagerCompatModuleImpl(
}

fun setTranslucent(translucent: Boolean) {
if (!isEnabled()) {
return original.setTranslucent(translucent)
}

UiThreadUtil.runOnUiThread {
val view = mReactContext.rootView?.findViewWithTag<EdgeToEdgeReactViewGroup>(EdgeToEdgeReactViewGroup.VIEW_TAG)
view?.forceStatusBarTranslucent(translucent)
view()?.forceStatusBarTranslucent(translucent)
}
}

fun setStyle(style: String) {
if (!isEnabled()) {
return original.setStyle(style)
}

UiThreadUtil.runOnUiThread {
getController()?.isAppearanceLightStatusBars = style == "dark-content"
}
}

fun getConstants(): MutableMap<String, Any>? = original.constants

private fun getController(): WindowInsetsControllerCompat? {
val activity = mReactContext.currentActivity

Expand All @@ -94,8 +113,13 @@ class StatusBarManagerCompatModuleImpl(
return this.controller
}

private fun isEnabled(): Boolean = view()?.active ?: false

private fun view(): EdgeToEdgeReactViewGroup? =
mReactContext.rootView?.findViewWithTag<EdgeToEdgeReactViewGroup>(EdgeToEdgeReactViewGroup.VIEW_TAG)

companion object {
const val NAME = "StatusBarManagerCompat"
const val NAME = "StatusBarManager"
private const val DEFAULT_ANIMATION_TIME = 300L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ class EdgeToEdgeReactViewGroup(
private var isStatusBarTranslucent = false
private var isNavigationBarTranslucent = false
private var isPreservingEdgeToEdge = false
private var active = false
private var isEdgeToEdge = false
var active: Boolean = false
set(value) {
field = value
if (value) {
enable()
} else {
disable()
}
}

// internal class members
private var eventView: ReactViewGroup? = null
Expand Down Expand Up @@ -223,16 +231,6 @@ class EdgeToEdgeReactViewGroup(
fun setPreserveEdgeToEdge(isPreservingEdgeToEdge: Boolean) {
this.isPreservingEdgeToEdge = isPreservingEdgeToEdge
}

fun setActive(active: Boolean) {
this.active = active

if (active) {
this.enable()
} else {
this.disable()
}
}
// endregion

// region external methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class StatusBarManagerCompatModule(

override fun getName(): String = StatusBarManagerCompatModuleImpl.NAME

override fun getConstants(): MutableMap<String, Any>? = module.getConstants()

@ReactMethod
private fun setHidden(hidden: Boolean) {
module.setHidden(hidden)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class KeyboardControllerPackage : TurboReactPackage() {
ReactModuleInfo(
StatusBarManagerCompatModuleImpl.NAME,
StatusBarManagerCompatModuleImpl.NAME,
false, // canOverrideExistingModule
true, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
Expand Down
12 changes: 1 addition & 11 deletions src/animated.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint react/jsx-sort-props: off */
import React, { useLayoutEffect, useMemo, useRef, useState } from "react";
import React, { useMemo, useRef, useState } from "react";
import { Animated, Platform, StyleSheet } from "react-native";
import {
controlEdgeToEdgeValues,
Expand All @@ -11,7 +11,6 @@ import { KeyboardControllerView } from "./bindings";
import { KeyboardContext } from "./context";
import { focusedInputEventsMap, keyboardEventsMap } from "./event-mappings";
import { useAnimatedValue, useEventHandlerRegistration } from "./internal";
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
import {
useAnimatedKeyboardHandler,
useFocusedInputLayoutHandler,
Expand Down Expand Up @@ -216,15 +215,6 @@ export const KeyboardProvider = (props: KeyboardProviderProps) => {
[],
);

// layout effects
useLayoutEffect(() => {
if (enabled) {
applyMonkeyPatch();
} else {
revertMonkeyPatch();
}
}, [enabled]);

if (__DEV__) {
controlEdgeToEdgeValues({
statusBarTranslucent,
Expand Down
41 changes: 0 additions & 41 deletions src/monkey-patch.android.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/monkey-patch.ts

This file was deleted.