Skip to content

feat: add navigationBarTranslucent prop #120

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 1 commit into from
Feb 28, 2023
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 @@ -27,6 +27,10 @@ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : Re
return manager.setStatusBarTranslucent(view, value)
}

override fun setNavigationBarTranslucent(view: ReactViewGroup, value: Boolean) {
return manager.setNavigationBarTranslucent(view, value)
}

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
return manager.getExportedCustomDirectEventTypeConstants()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicationContext) {
private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
private var isStatusBarTranslucent = false
private var isNavigationBarTranslucent = false

fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
val view = EdgeToEdgeReactViewGroup(reactContext)
Expand Down Expand Up @@ -44,7 +45,7 @@ class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicat
0,
if (this.isStatusBarTranslucent) 0 else insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0,
0,
insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0,
if (this.isNavigationBarTranslucent) 0 else insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0,
)

insets
Expand All @@ -61,6 +62,10 @@ class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicat
this.isStatusBarTranslucent = isStatusBarTranslucent
}

fun setNavigationBarTranslucent(view: ReactViewGroup, isNavigationBarTranslucent: Boolean) {
this.isNavigationBarTranslucent = isNavigationBarTranslucent
}

fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
val map: MutableMap<String, Any> = MapBuilder.of(
"topKeyboardMove",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : Re
manager.setStatusBarTranslucent(view, isStatusBarTranslucent)
}

@ReactProp(name = "navigationBarTranslucent")
fun setNavigationBarTranslucent(view: ReactViewGroup, isNavigationBarTranslucent: Boolean) {
manager.setNavigationBarTranslucent(view, isNavigationBarTranslucent)
}

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
return manager.getExportedCustomDirectEventTypeConstants()
}
Expand Down
10 changes: 10 additions & 0 deletions src/animated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ type KeyboardProviderProps = {
* @platform android
*/
statusBarTranslucent?: boolean;
/**
* Set the value to `true`, if you use translucent navigation bar on Android.
* Defaults to `false`.
*
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
* @platform android
*/
navigationBarTranslucent?: boolean;
};

export const KeyboardProvider = ({
children,
statusBarTranslucent,
navigationBarTranslucent,
}: KeyboardProviderProps) => {
// animated values
const progress = useAnimatedValue(0);
Expand Down Expand Up @@ -131,6 +140,7 @@ export const KeyboardProvider = ({
onKeyboardMoveReanimated={handler}
onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}
onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}
navigationBarTranslucent={navigationBarTranslucent}
statusBarTranslucent={statusBarTranslucent}
style={styles.container}
>
Expand Down
1 change: 1 addition & 0 deletions src/specs/KeyboardControllerViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type KeyboardMoveEvent = Readonly<{
export interface NativeProps extends ViewProps {
// props
statusBarTranslucent?: boolean;
navigationBarTranslucent?: boolean;
// callbacks
onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;
onKeyboardMoveStart?: DirectEventHandler<KeyboardMoveEvent>;
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type KeyboardControllerProps = {
e: NativeSyntheticEvent<EventWithName<NativeEvent>>
) => void;
statusBarTranslucent?: boolean;
navigationBarTranslucent?: boolean;
} & ViewProps;

export type KeyboardControllerModule = {
Expand Down