@react-navigation/core
Advanced tools
Comparing version 6.4.13 to 6.4.14
@@ -193,15 +193,51 @@ "use strict"; | ||
var _config$pattern; | ||
const matchedParams = (_config$pattern = config.pattern) === null || _config$pattern === void 0 ? void 0 : _config$pattern.split('/').filter(p => p.startsWith(':')).reduce((acc, p, i) => Object.assign(acc, { | ||
const matchResult = (_config$pattern = config.pattern) === null || _config$pattern === void 0 ? void 0 : _config$pattern.split('/').reduce((acc, p, index) => { | ||
if (!p.startsWith(':')) { | ||
return acc; | ||
} | ||
// Path parameter so increment position for the segment | ||
acc.pos += 1; | ||
const decodedParamSegment = decodeURIComponent( | ||
// The param segments appear every second item starting from 2 in the regex match result | ||
[p]: match[(i + 1) * 2].replace(/\//, '') | ||
}), {}); | ||
match[(acc.pos + 1) * 2]); | ||
Object.assign(acc.matchedParams, { | ||
[p]: Object.assign(acc.matchedParams[p] || {}, { | ||
[index]: decodedParamSegment.replace(/\//, '') | ||
}) | ||
}); | ||
return acc; | ||
}, { | ||
pos: -1, | ||
matchedParams: {} | ||
}); | ||
const matchedParams = matchResult.matchedParams || {}; | ||
routes = config.routeNames.map(name => { | ||
var _config$path; | ||
const config = configs.find(c => c.screen === name); | ||
const params = config === null || config === void 0 ? void 0 : (_config$path = config.path) === null || _config$path === void 0 ? void 0 : _config$path.split('/').filter(p => p.startsWith(':')).reduce((acc, p) => { | ||
const value = matchedParams[p]; | ||
var _routeConfig$pattern$; | ||
const routeConfig = configs.find(c => { | ||
// Check matching name AND pattern in case same screen is used at different levels in config | ||
return c.screen === name && config.pattern.startsWith(c.pattern); | ||
}); | ||
// Normalize pattern to remove any leading, trailing slashes, duplicate slashes etc. | ||
const normalizedPath = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path.split('/').filter(Boolean).join('/'); | ||
// Get the number of segments in the initial pattern | ||
const numInitialSegments = routeConfig === null || routeConfig === void 0 ? void 0 : (_routeConfig$pattern$ = routeConfig.pattern | ||
// Extract the prefix from the pattern by removing the ending path pattern (e.g pattern=`a/b/c/d` and normalizedPath=`c/d` becomes `a/b`) | ||
.replace(new RegExp(`${(0, _escapeStringRegexp.default)(normalizedPath)}$`), '')) === null || _routeConfig$pattern$ === void 0 ? void 0 : _routeConfig$pattern$.split('/').length; | ||
const params = normalizedPath === null || normalizedPath === void 0 ? void 0 : normalizedPath.split('/').reduce((acc, p, index) => { | ||
var _matchedParams$p; | ||
if (!p.startsWith(':')) { | ||
return acc; | ||
} | ||
// Get the real index of the path parameter in the matched path | ||
// by offsetting by the number of segments in the initial pattern | ||
const offset = numInitialSegments ? numInitialSegments - 1 : 0; | ||
const value = (_matchedParams$p = matchedParams[p]) === null || _matchedParams$p === void 0 ? void 0 : _matchedParams$p[index + offset]; | ||
if (value) { | ||
var _config$parse; | ||
var _routeConfig$parse; | ||
const key = p.replace(/^:/, '').replace(/\?$/, ''); | ||
acc[key] = (_config$parse = config.parse) !== null && _config$parse !== void 0 && _config$parse[key] ? config.parse[key](value) : value; | ||
acc[key] = routeConfig !== null && routeConfig !== void 0 && (_routeConfig$parse = routeConfig.parse) !== null && _routeConfig$parse !== void 0 && _routeConfig$parse[key] ? routeConfig.parse[key](value) : value; | ||
} | ||
@@ -208,0 +244,0 @@ return acc; |
@@ -184,15 +184,51 @@ import escape from 'escape-string-regexp'; | ||
var _config$pattern; | ||
const matchedParams = (_config$pattern = config.pattern) === null || _config$pattern === void 0 ? void 0 : _config$pattern.split('/').filter(p => p.startsWith(':')).reduce((acc, p, i) => Object.assign(acc, { | ||
const matchResult = (_config$pattern = config.pattern) === null || _config$pattern === void 0 ? void 0 : _config$pattern.split('/').reduce((acc, p, index) => { | ||
if (!p.startsWith(':')) { | ||
return acc; | ||
} | ||
// Path parameter so increment position for the segment | ||
acc.pos += 1; | ||
const decodedParamSegment = decodeURIComponent( | ||
// The param segments appear every second item starting from 2 in the regex match result | ||
[p]: match[(i + 1) * 2].replace(/\//, '') | ||
}), {}); | ||
match[(acc.pos + 1) * 2]); | ||
Object.assign(acc.matchedParams, { | ||
[p]: Object.assign(acc.matchedParams[p] || {}, { | ||
[index]: decodedParamSegment.replace(/\//, '') | ||
}) | ||
}); | ||
return acc; | ||
}, { | ||
pos: -1, | ||
matchedParams: {} | ||
}); | ||
const matchedParams = matchResult.matchedParams || {}; | ||
routes = config.routeNames.map(name => { | ||
var _config$path; | ||
const config = configs.find(c => c.screen === name); | ||
const params = config === null || config === void 0 ? void 0 : (_config$path = config.path) === null || _config$path === void 0 ? void 0 : _config$path.split('/').filter(p => p.startsWith(':')).reduce((acc, p) => { | ||
const value = matchedParams[p]; | ||
var _routeConfig$pattern$; | ||
const routeConfig = configs.find(c => { | ||
// Check matching name AND pattern in case same screen is used at different levels in config | ||
return c.screen === name && config.pattern.startsWith(c.pattern); | ||
}); | ||
// Normalize pattern to remove any leading, trailing slashes, duplicate slashes etc. | ||
const normalizedPath = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.path.split('/').filter(Boolean).join('/'); | ||
// Get the number of segments in the initial pattern | ||
const numInitialSegments = routeConfig === null || routeConfig === void 0 ? void 0 : (_routeConfig$pattern$ = routeConfig.pattern | ||
// Extract the prefix from the pattern by removing the ending path pattern (e.g pattern=`a/b/c/d` and normalizedPath=`c/d` becomes `a/b`) | ||
.replace(new RegExp(`${escape(normalizedPath)}$`), '')) === null || _routeConfig$pattern$ === void 0 ? void 0 : _routeConfig$pattern$.split('/').length; | ||
const params = normalizedPath === null || normalizedPath === void 0 ? void 0 : normalizedPath.split('/').reduce((acc, p, index) => { | ||
var _matchedParams$p; | ||
if (!p.startsWith(':')) { | ||
return acc; | ||
} | ||
// Get the real index of the path parameter in the matched path | ||
// by offsetting by the number of segments in the initial pattern | ||
const offset = numInitialSegments ? numInitialSegments - 1 : 0; | ||
const value = (_matchedParams$p = matchedParams[p]) === null || _matchedParams$p === void 0 ? void 0 : _matchedParams$p[index + offset]; | ||
if (value) { | ||
var _config$parse; | ||
var _routeConfig$parse; | ||
const key = p.replace(/^:/, '').replace(/\?$/, ''); | ||
acc[key] = (_config$parse = config.parse) !== null && _config$parse !== void 0 && _config$parse[key] ? config.parse[key](value) : value; | ||
acc[key] = routeConfig !== null && routeConfig !== void 0 && (_routeConfig$parse = routeConfig.parse) !== null && _routeConfig$parse !== void 0 && _routeConfig$parse[key] ? routeConfig.parse[key](value) : value; | ||
} | ||
@@ -199,0 +235,0 @@ return acc; |
@@ -308,3 +308,3 @@ import type { DefaultRouterOptions, InitialState, NavigationAction, NavigationState, ParamListBase, PartialState, Route } from '@react-navigation/routers'; | ||
export type ScreenListeners<State extends NavigationState, EventMap extends EventMapBase> = Partial<{ | ||
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<EventMap, EventName>; | ||
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<EventMap & EventMapCore<State>, EventName>; | ||
}>; | ||
@@ -311,0 +311,0 @@ type ScreenComponentType<ParamList extends ParamListBase, RouteName extends keyof ParamList> = React.ComponentType<{ |
{ | ||
"name": "@react-navigation/core", | ||
"description": "Core utilities for building navigators", | ||
"version": "6.4.13", | ||
"version": "6.4.14", | ||
"keywords": [ | ||
@@ -73,3 +73,3 @@ "react", | ||
}, | ||
"gitHead": "523fa4f3afb7c428a8370bfd83933c0163224e66" | ||
"gitHead": "95fe61ff61a0893626913ad1cc6cf902f5ecb3a1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
851135
13951