Skip to content

Commit

Permalink
fix patch v3
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgrzybowski committed Aug 8, 2023
1 parent 7cb8726 commit 2624a1a
Showing 1 changed file with 60 additions and 16 deletions.
76 changes: 60 additions & 16 deletions patches/@react-navigation+native+6.1.6.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
diff --git a/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js b/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js
index 16fdbef..40ee421 100644
index 16fdbef..bc2c96a 100644
--- a/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js
+++ b/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js
@@ -2,7 +2,21 @@ import { nanoid } from 'nanoid/non-secure';
@@ -1,8 +1,23 @@
import { nanoid } from 'nanoid/non-secure';
+import { findFocusedRouteKey } from './findFocusedRouteKey';
export default function createMemoryHistory() {
let index = 0;
let items = [];
Expand All @@ -25,7 +27,7 @@ index 16fdbef..40ee421 100644
// Pending callbacks for `history.go(n)`
// We might modify the callback stored if it was interrupted, so we have a ref to identify it
const pending = [];
@@ -16,6 +30,9 @@ export default function createMemoryHistory() {
@@ -16,6 +31,9 @@ export default function createMemoryHistory() {
});
};
const history = {
Expand All @@ -35,7 +37,23 @@ index 16fdbef..40ee421 100644
get index() {
var _window$history$state;
// We store an id in the state instead of an index
@@ -68,7 +85,9 @@ export default function createMemoryHistory() {
@@ -32,12 +50,13 @@ export default function createMemoryHistory() {
},
backIndex(_ref) {
let {
- path
+ path,
+ state
} = _ref;
// We need to find the index from the element before current to get closest path to go back to
for (let i = index - 1; i >= 0; i--) {
const item = items[i];
- if (item.path === path) {
+ if (item.path === path && findFocusedRouteKey(item.state) === findFocusedRouteKey(state)) {
return i;
}
}
@@ -68,7 +87,9 @@ export default function createMemoryHistory() {
window.history.pushState({
id
}, '', path);
Expand All @@ -45,7 +63,7 @@ index 16fdbef..40ee421 100644
replace(_ref3) {
var _window$history$state2;
let {
@@ -108,7 +127,9 @@ export default function createMemoryHistory() {
@@ -108,7 +129,9 @@ export default function createMemoryHistory() {
window.history.replaceState({
id
}, '', pathWithHash);
Expand All @@ -55,7 +73,7 @@ index 16fdbef..40ee421 100644
// `history.go(n)` is asynchronous, there are couple of things to keep in mind:
// - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.
// - each `history.go(n)` call will trigger a separate `popstate` event with correct location.
@@ -175,20 +196,17 @@ export default function createMemoryHistory() {
@@ -175,20 +198,17 @@ export default function createMemoryHistory() {
// But on Firefox, it seems to take much longer, around 50ms from our testing
// We're using a hacky timeout since there doesn't seem to be way to know for sure
const timer = setTimeout(() => {
Expand All @@ -82,7 +100,7 @@ index 16fdbef..40ee421 100644
const last = pending.pop();
window.removeEventListener('popstate', onPopState);
last === null || last === void 0 ? void 0 : last.cb();
@@ -202,12 +220,17 @@ export default function createMemoryHistory() {
@@ -202,12 +222,17 @@ export default function createMemoryHistory() {
// Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
listen(listener) {
const onPopState = () => {
Expand All @@ -100,19 +118,36 @@ index 16fdbef..40ee421 100644
window.addEventListener('popstate', onPopState);
return () => window.removeEventListener('popstate', onPopState);
}
diff --git a/node_modules/@react-navigation/native/lib/module/findFocusedRouteKey.js b/node_modules/@react-navigation/native/lib/module/findFocusedRouteKey.js
new file mode 100644
index 0000000..16da117
--- /dev/null
+++ b/node_modules/@react-navigation/native/lib/module/findFocusedRouteKey.js
@@ -0,0 +1,7 @@
+import { findFocusedRoute } from '@react-navigation/core';
+export const findFocusedRouteKey = state => {
+ var _findFocusedRoute;
+ // @ts-ignore
+ return (_findFocusedRoute = findFocusedRoute(state)) === null || _findFocusedRoute === void 0 ? void 0 : _findFocusedRoute.key;
+};
+//# sourceMappingURL=findFocusedRouteKey.js.map
\ No newline at end of file
diff --git a/node_modules/@react-navigation/native/lib/module/useLinking.js b/node_modules/@react-navigation/native/lib/module/useLinking.js
index 5bf2a88..72f1204 100644
index 5bf2a88..a6d0670 100644
--- a/node_modules/@react-navigation/native/lib/module/useLinking.js
+++ b/node_modules/@react-navigation/native/lib/module/useLinking.js
@@ -60,6 +60,49 @@ const series = cb => {
@@ -2,6 +2,7 @@ import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getP
import isEqual from 'fast-deep-equal';
import * as React from 'react';
import createMemoryHistory from './createMemoryHistory';
+import { findFocusedRouteKey } from './findFocusedRouteKey';
import ServerContext from './ServerContext';
/**
* Find the matching navigation state that changed between 2 navigation states
@@ -60,6 +61,44 @@ const series = cb => {
return callback;
};
let linkingHandlers = [];
+const findFocusedRouteKey = state => {
+ var _findFocusedRoute;
+ // @ts-ignore
+ return (_findFocusedRoute = findFocusedRoute(state)) === null || _findFocusedRoute === void 0 ? void 0 : _findFocusedRoute.key;
+};
+const getAllStateKeys = state => {
+ let current = state;
+ const keys = [];
Expand Down Expand Up @@ -154,7 +189,7 @@ index 5bf2a88..72f1204 100644
export default function useLinking(ref, _ref) {
let {
independent,
@@ -251,6 +294,9 @@ export default function useLinking(ref, _ref) {
@@ -251,6 +290,9 @@ export default function useLinking(ref, _ref) {
// Otherwise it's likely a change triggered by `popstate`
path !== pendingPath) {
const historyDelta = (focusedState.history ? focusedState.history.length : focusedState.routes.length) - (previousFocusedState.history ? previousFocusedState.history.length : previousFocusedState.routes.length);
Expand All @@ -164,7 +199,16 @@ index 5bf2a88..72f1204 100644
if (historyDelta > 0) {
// If history length is increased, we should pushState
// Note that path might not actually change here, for example, drawer open should pushState
@@ -269,27 +315,47 @@ export default function useLinking(ref, _ref) {
@@ -262,34 +304,55 @@ export default function useLinking(ref, _ref) {
// If history length is decreased, i.e. entries were removed, we want to go back

const nextIndex = history.backIndex({
- path
+ path,
+ state
});
const currentIndex = history.index;
try {
if (nextIndex !== -1 && nextIndex < currentIndex) {
// An existing entry for this path exists and it's less than current index, go back to that
await history.go(nextIndex - currentIndex);
Expand Down

0 comments on commit 2624a1a

Please sign in to comment.