expo / react-native-action-sheet

A cross-platform ActionSheet for React Native
MIT License
1.37k stars 224 forks source link

Functions on ActionSheetProvider ref are all undefined #252

Open mikeislearning opened 2 years ago

mikeislearning commented 2 years ago

I created an exportable ref with export const actionSheetRef = React.createRef<ActionSheetProvider>(), and applied it to the ActionSheetProvider. When I then try to access it, using either actionSheetRef.current or actionSheetRef.current._actionSheetRef.current, all the typed functions don't seem to be accessible, even though the typescript definition file shows this:

export default class ActionSheet extends React.Component<Props, State> {
    static defaultProps: {
        useNativeDriver: boolean;
    };
    _actionSheetHeight: number;
    state: State;
    _deferNextShow?: () => void;
    _setActionSheetHeight: ({ nativeEvent }: any) => any;
    render(): JSX.Element;
    _renderSheet(): JSX.Element | null;
    showActionSheetWithOptions: (options: ActionSheetOptions, onSelect: (i: number) => void) => void;
    _selectCancelButton: () => boolean;
    _onSelect: (index: number) => boolean;
    _animateOut: () => boolean;
}

I'd like to programatically close the action sheet using either _animateOut or _selectedCancelButton, but accessing that key returns undefined.

Has anyone had any luck getting ref to work properly?

bradbyte commented 2 years ago

I haven't tested this, but we probably need to tap into the imperative ref hook that would expose those internal methods to a parent.