mirror of
https://github.com/expo/react-native-action-sheet.git
synced 2026-11-14 19:11:42 -10:00
fix: stabilize the identity of the context provider value (#251)
This commit is contained in:
1 parent
bd0c001215
commit
55005ba0fb
1 file changed
+11
-8
@@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
|
||||
import ActionSheet from './ActionSheet';
|
||||
import { Provider } from './context';
|
||||
import { ActionSheetOptions } from './types';
|
||||
import { ActionSheetOptions, ActionSheetProps } from './types';
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
@@ -11,24 +11,27 @@ interface Props {
|
||||
|
||||
export default class ActionSheetProvider extends React.Component<Props> {
|
||||
_actionSheetRef: React.RefObject<ActionSheet>;
|
||||
_context: ActionSheetProps;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this._actionSheetRef = React.createRef();
|
||||
}
|
||||
|
||||
getContext = () => {
|
||||
return {
|
||||
this._context = {
|
||||
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => {
|
||||
this._actionSheetRef.current !== null &&
|
||||
if (this._actionSheetRef.current != null) {
|
||||
this._actionSheetRef.current.showActionSheetWithOptions(options, callback);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
getContext(): ActionSheetProps {
|
||||
return this._context;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Provider value={this.getContext()}>
|
||||
<Provider value={this._context}>
|
||||
<ActionSheet ref={this._actionSheetRef} useNativeDriver={this.props.useNativeDriver}>
|
||||
{React.Children.only(this.props.children)}
|
||||
</ActionSheet>
|
||||
|
||||
Reference in new issue
Block a user