Skip to content

Android side-effect issue with KeyboardProvider #584

Closed
@hyochan

Description

@hyochan

Describe the bug
Hello, thank you for creating such a great library. I've been using KeyboardAvoidingView in React Native for a while, but recently needed the keyboard functionality from react-native-keyboard-controller, which allowed me to implement the keyboard behavior I wanted. I really appreciate your work.

However, I encountered an issue where KeyboardAvoidingView from the core react-native package only causes a side-effect on Android. Specifically, when I wrap my app layout with KeyboardProvider, the KeyboardAvoidingView in react-native package stops working, but this issue is only happening on Android.

It seems like the issue was resolved by setting padding instead of leaving the behavior as undefined, and also by providing a keyboardVerticalOffset, but the exact cause and behavior remain unclear, which leaves me feeling a bit uncertain. I would like to better understand how this change impacts screens where KeyboardAvoidingView is already being used. Specifically, I’d like to know what effects this adjustment may have on the existing views, especially in terms of layout shifts or keyboard interaction, and whether this might introduce any potential side effects. Could you explain how this configuration influences the layout and behavior in detail?

Code snippet
RootProvider.tsx

function RootProvider({initialThemeType, children}: Props): JSX.Element {
  return (
    <KeyboardProvider>
      <RecoilRoot>
        <DoobooProvider
          themeConfig={{
            initialThemeType: initialThemeType ?? undefined,
            customTheme: theme,
          }}
        >
          <ErrorBoundary
            FallbackComponent={FallbackComponent}
            onError={handleErrorConsole}
          >
            <ActionSheetProvider>{children}</ActionSheetProvider>
          </ErrorBoundary>
        </DoobooProvider>
      </RecoilRoot>
    </KeyboardProvider>
  );
}

_layout.tsx

    <GestureHandlerRootView
      style={css`
        flex: 1;
      `}
    >
      <RootProvider initialThemeType={localThemeType as ColorSchemeName}>
        <>
          <StatusBarBrightness />
          <Layout />
        </>
      </RootProvider>
    </GestureHandlerRootView>

index.tsx

import styled, {css} from '@emotion/native';
import {EditText, IconButton, Typography, useDooboo} from 'dooboo-ui';
import {Stack} from 'expo-router';

import {t} from '../src/STRINGS';
import {KeyboardAvoidingView, Platform, View} from 'react-native';
import {useState} from 'react';

const Container = styled.View`
  background-color: ${({theme}) => theme.bg.basic};

  flex: 1;
  align-self: stretch;
  justify-content: center;
  align-items: center;
`;

export default function Index(): JSX.Element {
  const {theme} = useDooboo();
  const [text, setText] = useState('');

  return (
    <Container>
      <Stack.Screen
        options={{
          title: t('HOME'),
        }}
      />
      <KeyboardAvoidingView
        style={css`
          flex: 1;
          width: 100%;
        `}
        behavior={Platform.OS === 'ios' ? 'padding' : undefined}
      >
        <View
          style={css`
            flex: 1;
            background-color: ${theme.bg.paper};

            justify-content: center;
            align-items: center;
          `}
        >
          <Typography.Heading5>Hi there!</Typography.Heading5>
        </View>
        <EditText
          onChangeText={setText}
          value={text}
          decoration="boxed"
          style={css`
            background-color: ${theme.bg.basic};
          `}
          endElement={<IconButton icon="Bird" onPress={() => {}} size={24} />}
        />
      </KeyboardAvoidingView>
    </Container>
  );
}

Repo for reproducing
I would be highly appreciate if you can provide repository for reproducing your issue. It can significantly reduce the time for discovering and fixing the problem.

To Reproduce
Steps to reproduce the behavior:

  1. Go and clone react-native-keyboard-controller-issue repository.
  2. Run bun install or use your package manager.
  3. Checkout initial commit git checkout 16a313a4d8ae1d4a5fb1cdd07529f440527c3dcb.
  4. Run the app and see it if works.
  5. Checkout commit 41f812e9b6edd1b27cf787f74de7600ae20360fe which installed react-native-keyboard-controller and wrapped with KeyboardProvider and test that keyboard is not showing this time.
  6. Checkout commit 61bc6f35ffc30048df04c4a78a8a2a1d29de2d90 and test that it works again with workaround codes.
  7. Also tested using custom hook, useKeyboardAnimation with various options.

Expected behavior
Even when using react-native-keyboard-controller and wrapping the app with KeyboardProvider, the existing KeyboardAvoidingView from react-native should continue to function without issues on Android.

Screenshots

Video Previews

1. Initial Commit

16a313a.mp4

2. Install and wrap with KeyboardProvider

41f812e.mp4

3. Naive workaround

61bc6f3.mp4

4. Test other options with useKeyboardAnimation

dd8d452.mp4

Smartphone (please complete the following information):

  • Device: All Android Phones
  • OS: Android
  • RN version: 0.74.5
  • RN architecture: old
  • JS engine: Hermes
  • Library version: 1.13.4

Additional context
N/A

Metadata

Metadata

Assignees

Labels

KeyboardAvoidingView 🧪Anything related to KeyboardAvoidingView componentquestionYou wanted to clarify something about the usage of the library or have a question about something

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions