mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 17:34:59 +08:00
refactor: drop shouldActionPropagateToChildren
This commit is contained in:
committed by
Satyajit Sahoo
parent
e0bee10e6b
commit
89c279fb23
@@ -75,15 +75,6 @@ const BaseRouter = {
|
||||
}
|
||||
},
|
||||
|
||||
shouldActionPropagateToChildren(action: CommonAction) {
|
||||
return (
|
||||
action.type === 'NAVIGATE' ||
|
||||
action.type === 'REPLACE' ||
|
||||
action.type === 'SET_PARAMS' ||
|
||||
action.type === 'RESET'
|
||||
);
|
||||
},
|
||||
|
||||
shouldActionChangeFocus(action: CommonAction) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
@@ -124,17 +124,7 @@ it('throws when nesting performTransaction', () => {
|
||||
});
|
||||
|
||||
it('handle dispatching with ref', () => {
|
||||
function CurrentParentRouter(options: DefaultRouterOptions) {
|
||||
const CurrentMockRouter = MockRouter(options);
|
||||
const ParentRouter: Router<NavigationState, MockActions> = {
|
||||
...CurrentMockRouter,
|
||||
|
||||
shouldActionPropagateToChildren() {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
return ParentRouter;
|
||||
}
|
||||
const CurrentParentRouter = MockRouter;
|
||||
|
||||
function CurrentChildRouter(options: DefaultRouterOptions) {
|
||||
const CurrentMockRouter = MockRouter(options);
|
||||
|
||||
@@ -93,10 +93,6 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
||||
}
|
||||
},
|
||||
|
||||
shouldActionPropagateToChildren(action) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
shouldActionChangeFocus() {
|
||||
return false;
|
||||
},
|
||||
|
||||
@@ -87,17 +87,7 @@ it("lets parent handle the action if child didn't", () => {
|
||||
});
|
||||
|
||||
it("lets children handle the action if parent didn't", () => {
|
||||
function CurrentParentRouter(options: DefaultRouterOptions) {
|
||||
const CurrentMockRouter = MockRouter(options);
|
||||
const ParentRouter: Router<NavigationState, MockActions> = {
|
||||
...CurrentMockRouter,
|
||||
|
||||
shouldActionPropagateToChildren() {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
return ParentRouter;
|
||||
}
|
||||
const CurrentParentRouter = MockRouter;
|
||||
|
||||
function CurrentChildRouter(options: DefaultRouterOptions) {
|
||||
const CurrentMockRouter = MockRouter(options);
|
||||
@@ -221,17 +211,7 @@ it("lets children handle the action if parent didn't", () => {
|
||||
});
|
||||
|
||||
it("doesn't crash if no navigator handled the action", () => {
|
||||
function TestRouter(options: DefaultRouterOptions) {
|
||||
const router: Router<NavigationState, MockActions> = {
|
||||
...MockRouter(options),
|
||||
|
||||
shouldActionPropagateToChildren() {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
return router;
|
||||
}
|
||||
const TestRouter = MockRouter;
|
||||
|
||||
const TestNavigator = (props: any) => {
|
||||
const { state, descriptors } = useNavigationBuilder(TestRouter, props);
|
||||
|
||||
@@ -139,14 +139,6 @@ export type Router<
|
||||
*/
|
||||
getStateForAction(state: State, action: Action): State | null;
|
||||
|
||||
/**
|
||||
* Whether the action bubbles to other navigators
|
||||
* When an action isn't handled by current navigator, it can be passed to nested navigators
|
||||
*
|
||||
* @param action Action object to check.
|
||||
*/
|
||||
shouldActionPropagateToChildren(action: NavigationAction): boolean;
|
||||
|
||||
/**
|
||||
* Whether the action should also change focus in parent navigator
|
||||
*
|
||||
|
||||
@@ -67,13 +67,11 @@ export default function useOnAction({
|
||||
}
|
||||
}
|
||||
|
||||
if (router.shouldActionPropagateToChildren(action)) {
|
||||
for (let i = listeners.length - 1; i >= 0; i--) {
|
||||
const listener = listeners[i];
|
||||
for (let i = listeners.length - 1; i >= 0; i--) {
|
||||
const listener = listeners[i];
|
||||
|
||||
if (listener(action, visitedNavigators)) {
|
||||
return true;
|
||||
}
|
||||
if (listener(action, visitedNavigators)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -199,10 +199,6 @@ export default function TabRouter({
|
||||
}
|
||||
},
|
||||
|
||||
shouldActionPropagateToChildren(action) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
shouldActionChangeFocus(action) {
|
||||
return action.type === 'NAVIGATE';
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user