gluestack-ui icon indicating copy to clipboard operation
gluestack-ui copied to clipboard

keyboardAvoidingView not working with Actionsheet on ios

Open faorte opened this issue 1 year ago • 6 comments

Description

Trying your example for keyboardAvoidingView when you are using ActionSheet but it does not work on ios

CodeSandbox/Snack link

No response

Steps to reproduce

  1. add example code from your website to project:

function App() { const [showActionsheet, setShowActionsheet] = React.useState(false) const handleClose = () => setShowActionsheet(!showActionsheet) return ( <> <Button onPress={handleClose}> <ButtonText>Open</ButtonText> </Button> <KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : undefined} > <Actionsheet isOpen={showActionsheet} onClose={handleClose}> <ActionsheetBackdrop /> <ActionsheetContent maxHeight="75%"> <ActionsheetDragIndicatorWrapper> <ActionsheetDragIndicator /> </ActionsheetDragIndicatorWrapper> <VStack w="$full" p={20}> <HStack justifyContent="center" alignItems="center" space="md"> <Box w={50} h="$full" px="$2" borderWidth={1} borderStyle="solid" borderColor="$borderLight300" rounded="$sm" > <Image source={{ uri: "https://i.imgur.com/UwTLr26.png" }} flex={1} resizeMode="contain" /> </Box> <VStack flex={1}> <Text fontWeight="$bold">Mastercard</Text> <Text>Card ending in 2345</Text> </VStack> </HStack> <FormControl mt={36}> <FormControlLabel> <FormControlLabelText> Confirm security code </FormControlLabelText> </FormControlLabel> <Input w="$full"> <InputSlot> <InputIcon as={LeadingIcon} ml="$2" /> </InputSlot> <InputField placeholder="CVC/CVV" /> </Input> <Button onPress={handleClose} mt={20}> <ButtonText>Pay $1000</ButtonText> </Button> </FormControl> </VStack> </ActionsheetContent> </Actionsheet> </KeyboardAvoidingView> </> ) }

  1. toggle keyboard.
  2. its not moving the actionsheet properly

gluestack-ui Version

1.1.1

Platform

  • [X] Expo
  • [ ] React Native CLI
  • [ ] Next
  • [ ] Web
  • [ ] Android
  • [X] iOS

Other Platform

No response

Additional Information

No response

faorte avatar Jan 26 '24 12:01 faorte

@faorte Thanks for reporting this. We'll have a look.

surajahmed avatar Jan 31 '24 06:01 surajahmed

Hi @surajahmed , any update on this. Facing the same issue. Thanks

anup-a avatar Apr 25 '24 03:04 anup-a

@anup-a We're working on it. Please eject the components and try replacing ScrollView with View for Actionsheet content and wrap it with KeyboardAvoidingView for now. Please follow https://gluestack.io/ui/docs/home/theme-configuration/customizing-theme/eject-library

surajahmed avatar Apr 30 '24 13:04 surajahmed

Is there any estimate of when we can expect this to be fixed? We are also experiencing this issue.

altick avatar May 01 '24 11:05 altick

We're working on it. Hope to push the fix in the coming release. Thanks for your patience.

surajahmed avatar May 06 '24 10:05 surajahmed

@surajahmed

The problem apparently is with the Overlay.

It is possible to modify Actionsheet.tsx to listen to the Keyboard keyboardDidShow event and thus add a marginBottom: 200 when opening the keyboard.

File path: node_modules/@gluestack-ui/actionsheet/src/Actionsheet.tsx

An example, how to implement the solution:

const [isKeyboardVisible, setKeyboardVisible] = useState(false);

  useEffect(() => {
    const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {
      setKeyboardVisible(true);
    });
    const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => {
      setKeyboardVisible(false);
    });

    return () => {
      keyboardDidHideListener.remove();
      keyboardDidShowListener.remove();
    };
  }, []);

  return (
<Overlay
          isOpen={visible}
          onRequestClose={handleClose}
          isKeyboardDismissable={isKeyboardDismissable}
          useRNModal={useRNModal}
          // @ts-ignore
          style={{
            ...overlayStyle,
            ...(Platform.OS === 'ios' && { marginBottom: isKeyboardVisible ? 200 : undefined }),
          }}
        >
          <ActionsheetContext.Provider value={contextValue}>
            <StyledActionsheet
              ref={ref}
              style={[StyleSheet.absoluteFill]}
              {...(props as T)}
            >
              {children}
            </StyledActionsheet>
          </ActionsheetContext.Provider>
        </Overlay>
  );

This worked for me. It's not the best solution, but it works!

Sorry for my english.

leogaletti avatar Jun 15 '24 01:06 leogaletti