Skip to content

Commit

Permalink
changes to patch to include change in series function
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Aug 24, 2023
1 parent 61b3b63 commit 877c28d
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions patches/@react-navigation+native+6.1.6.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js b/node_modules/@react-navigation/native/lib/module/createMemoryHistory.js
index 16fdbef..8fca56f 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
@@ -1,8 +1,23 @@
Expand Down Expand Up @@ -73,15 +73,6 @@ index 16fdbef..8fca56f 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.
@@ -133,7 +156,7 @@ export default function createMemoryHistory() {
index = nextIndex;
}
if (n === 0) {
- return;
+ return Promise.resolve();
}

// When we call `history.go`, `popstate` will fire when there's history to go back to
@@ -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
Expand Down Expand Up @@ -142,7 +133,7 @@ index 0000000..16da117
+//# 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..da708ba 100644
index 5bf2a88..abfa7d7 100644
--- a/node_modules/@react-navigation/native/lib/module/useLinking.js
+++ b/node_modules/@react-navigation/native/lib/module/useLinking.js
@@ -2,6 +2,7 @@ import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getP
Expand All @@ -153,7 +144,7 @@ index 5bf2a88..da708ba 100644
import ServerContext from './ServerContext';
/**
* Find the matching navigation state that changed between 2 navigation states
@@ -34,32 +35,53 @@ const findMatchingState = (a, b) => {
@@ -34,32 +35,52 @@ const findMatchingState = (a, b) => {
/**
* Run async function in series as it's called.
*/
Expand Down Expand Up @@ -211,7 +202,6 @@ index 5bf2a88..da708ba 100644
+ }
+ return -1;
+};
+
+const getHistoryDeltaByKeys = (focusedState, previousFocusedState) => {
+ const focusedStateKeys = focusedState.routes.map(r => r.key);
+ const previousFocusedStateKeys = previousFocusedState.routes.map(r => r.key);
Expand All @@ -229,15 +219,17 @@ index 5bf2a88..da708ba 100644
export default function useLinking(ref, _ref) {
let {
independent,
@@ -251,6 +273,7 @@ export default function useLinking(ref, _ref) {
@@ -251,6 +272,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);
+
+ // The historyDelta and historyDeltaByKeys may differ if the new state has an entry that didn't exist in previous state
+ const historyDeltaByKeys = getHistoryDeltaByKeys(focusedState, previousFocusedState);
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
@@ -262,34 +285,63 @@ export default function useLinking(ref, _ref) {
@@ -262,34 +286,56 @@ 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({
Expand All @@ -250,7 +242,6 @@ index 5bf2a88..da708ba 100644
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);
+ // Store the updated state as well as fix the path if incorrect
+ history.replace({
+ path,
+ state
Expand All @@ -267,8 +258,6 @@ index 5bf2a88..da708ba 100644
- path,
- state
- });
+ // The historyDelta and historyDeltaByKeys may differ if the new state has an entry that didn't exist in previous state
+ const historyDeltaByKeys = getHistoryDeltaByKeys(focusedState, previousFocusedState);
+ await history.go(historyDeltaByKeys);
+ if (historyDeltaByKeys + 1 === historyDelta) {
+ history.push({
Expand Down Expand Up @@ -300,15 +289,11 @@ index 5bf2a88..da708ba 100644
+ state
+ });
+ } else {
+ try {
+ await history.go(-staleHistoryDiff);
+ history.push({
+ path,
+ state
+ });
+ } catch (e) {
+ // The navigation was interrupted
+ }
+ await history.go(-staleHistoryDiff);
+ history.push({
+ path,
+ state
+ });
+ }
}
} else {
Expand Down

0 comments on commit 877c28d

Please sign in to comment.