react-native-actions-sheet icon indicating copy to clipboard operation
react-native-actions-sheet copied to clipboard

action sheet is popped out of the screen when input is focused

Open JJJJune opened this issue 3 years ago • 10 comments

action sheet is popped out of the screen when input is focused. when i change the keyboard, action sheet scroll into view.Does anyone know how to fix this? https://user-images.githubusercontent.com/38945816/192695375-9e8bc285-e173-4419-9370-3b40e122cfe9.mp4

JJJJune avatar Sep 28 '22 05:09 JJJJune

When the input is focused, the sheet moves upward! I've the same issue. any update?

ayuleul avatar Oct 01 '22 15:10 ayuleul

Can you guys drop your implementation so i can replicate the issue?

ammarahm-ed avatar Oct 02 '22 03:10 ammarahm-ed

The same for me - sheet moves upward every time keyboard is triggered

const keyboardBehavior = Platform.select({
  android: false,
  default: true,
});

const DRAWER_MARGIN = 30

return (
 <ActionSheet
      headerAlwaysVisible
      animated
      gestureEnabled={gestureEnabled}
      isModal={false}
      keyboardHandlerEnabled={keyboardBehavior}>
      <KeyboardAvoidingView behavior="height" keyboardVerticalOffset={-DRAWER_MARGIN}>
        <SafeAreaView edges={['right', 'left', 'bottom']}>
          <ScrollView
            keyboardShouldPersistTaps="handled"
            showsVerticalScrollIndicator={false}
            bounces={false}>
            <AutocompleteDropdown />
            <Input />
            <Input />
            <Input />
          </ScrollView>
        </SafeAreaView>
      </KeyboardAvoidingView>
    </ActionSheet>
)

Also happened when AutocompleteDropdown from https://www.npmjs.com/package/react-native-autocomplete-dropdown changes its state

Can you guys drop your implementation so i can replicate the issue?

sofiiachkadua avatar Oct 02 '22 17:10 sofiiachkadua

Try removing KeyboardAvoidingView & SafeAreaView, you don't need those in the Sheet especially KeyboardAvoidingView can cause problems.

ammarahm-ed avatar Oct 03 '22 08:10 ammarahm-ed

In my case, I did it in the following manner:

`<ActionSheet

  id="feed-create-post-sheet"
  ref={actionSheetRef}
  containerStyle={styles.actionContainer}
  statusBarTranslucent
  drawUnderStatusBar={true}
  defaultOverlayOpacity={0.3}
  gestureEnabled={true}>
  <View style={styles.container}>
    <View style={styles.inputConStyle}>
        <TextInput
          value={message}
          onChangeText={handleMessageChange}
          multiline
          style={styles.input}
        />
    </View>
    <Button
      onPress={handle}
    />
  </View>
</ActionSheet>`

ayuleul avatar Oct 03 '22 08:10 ayuleul

Try removing KeyboardAvoidingView & SafeAreaView, you don't need those in the Sheet especially KeyboardAvoidingView can cause problems.

Hello! Thanks for tip. It helps for IOS, but not for Android( Drawer still jumps depending on input focus/unfocus

sofiiachkadua avatar Oct 06 '22 09:10 sofiiachkadua

Hi, try v0.8.8. It should fix keyboard issues.

ammarahm-ed avatar Oct 09 '22 13:10 ammarahm-ed

I solved it by two method. one is setting the marginbottom of the container to a negative number.
other way is set keyboardHandlerEnabled false

setp 1 : add hooks

import { useState, useEffect } from 'react';
import { Keyboard } from 'react-native';
import { isIOS } from 'utils/helper';

const useKeyboardOffset = () => {
  const [keyboardOffset, setKeyboardOffset] = useState(0);

  useEffect(() => {
    const keyboardDidShowListener = Keyboard.addListener(
      'keyboardDidShow',
      event => {
        if (isIOS) {
          setKeyboardOffset(event.endCoordinates.height);
        }
      },
    );

    const keyboardDidHideListener = Keyboard.addListener(
      'keyboardDidHide',
      () => {
        setKeyboardOffset(0);
      },
    );

    return () => {
      keyboardDidShowListener.remove();

      keyboardDidHideListener.remove();
    };
  }, []);

  return keyboardOffset;
};

export default useKeyboardOffset;

step 2: in your components use hooks


import useKeyboardOffset from 'hooks/useKeyboardOffset';
import { isIOS } from 'utils/helper';

const YourtComponet = () => {

 const keyboardOffset = useKeyboardOffset();
 const marginBottom = isIOS && keyboardOffset ? 90 - keyboardOffset : 0;

// other code

return (

<ActionSheet>
   <Container style={{
       marginBottom: marginBottom
    }}>
   </Container>
</ActionSheet>
)
}

another way is set keyboardHandlerEnabled false to the ActionSheet

<ActionSheet keyboardHandlerEnabled={false}>
...
</ActionSheet>

LeeRayno avatar Aug 16 '24 04:08 LeeRayno