mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-28 20:35:19 +08:00
feat: add native container with back button integration (#48)
This commit is contained in:
committed by
Satyajit Sahoo
parent
4a3db4e6f4
commit
b7735af7fc
@@ -99,8 +99,19 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
listeners[0](navigation => navigation.dispatch(action));
|
||||
};
|
||||
|
||||
const canGoBack = () => {
|
||||
const { result, handled } = listeners[0](navigation =>
|
||||
navigation.canGoBack()
|
||||
);
|
||||
|
||||
if (handled) {
|
||||
return result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
dispatch,
|
||||
...(Object.keys(BaseActions) as Array<keyof typeof BaseActions>).reduce<
|
||||
any
|
||||
>((acc, name) => {
|
||||
@@ -114,6 +125,8 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
);
|
||||
return acc;
|
||||
}, {}),
|
||||
dispatch,
|
||||
canGoBack,
|
||||
}));
|
||||
|
||||
const navigationStateRef = React.useRef<State>();
|
||||
|
||||
@@ -55,12 +55,13 @@ export default function useDescriptors<
|
||||
getState,
|
||||
setState,
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
onRouteFocus,
|
||||
router,
|
||||
emitter,
|
||||
addFocusedListener,
|
||||
}: Options<ScreenOptions>) {
|
||||
const [options, setOptions] = React.useState<{ [key: string]: object }>({});
|
||||
|
||||
const context = React.useMemo(
|
||||
() => ({
|
||||
navigation,
|
||||
|
||||
@@ -243,9 +243,9 @@ export default function useNavigationBuilder<
|
||||
setState,
|
||||
onRouteFocus,
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
router,
|
||||
emitter,
|
||||
addFocusedListener,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -35,7 +35,7 @@ export default function useNavigationHelpers<
|
||||
const { performTransaction } = React.useContext(NavigationStateContext);
|
||||
|
||||
return React.useMemo(() => {
|
||||
const dispatch = (action: Action | ((state: State) => State)) => {
|
||||
const dispatch = (action: Action | ((state: State) => State)) =>
|
||||
performTransaction(() => {
|
||||
if (typeof action === 'function') {
|
||||
setState(action(getState()));
|
||||
@@ -43,7 +43,6 @@ export default function useNavigationHelpers<
|
||||
onAction(action);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const actions = {
|
||||
...router.actionCreators,
|
||||
|
||||
Reference in New Issue
Block a user