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

Functions on ActionSheetProvider ref are all undefined

Open mikeislearning opened this issue 4 years ago • 1 comments

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?

mikeislearning avatar Dec 14 '21 17:12 mikeislearning

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.

bradbyte avatar Jan 10 '22 19:01 bradbyte