gluestack / gluestack-ui

React & React Native Components & Patterns (copy-paste components & patterns crafted with Tailwind CSS (NativeWind))
https://gluestack.io/
MIT License
2.71k stars 120 forks source link

keyboardAvoidingView not working with Actionsheet on ios #1709

Open faorte opened 9 months ago

faorte commented 9 months ago

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 ( <>

Mastercard Card ending in 2345 Confirm security code ) }` 2. toggle keyboard. 3. 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_
surajahmed commented 9 months ago

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

anup-a commented 6 months ago

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

surajahmed commented 6 months ago

@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

altick commented 6 months ago

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

surajahmed commented 6 months ago

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

leogaletti commented 5 months ago

@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.