mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-26 22:28:19 +08:00
Compare commits
14 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de2b6d8715 | ||
|
|
f22abb726c | ||
|
|
031c4d2378 | ||
|
|
2b5955efbe | ||
|
|
70f7e7a7c0 | ||
|
|
6cf1a041b2 | ||
|
|
0d8cdc8a27 | ||
|
|
2680b461a2 | ||
|
|
fb726eede3 | ||
|
|
3aaf6eb648 | ||
|
|
477c08858d | ||
|
|
300791ab49 | ||
|
|
3e92e22941 | ||
|
|
a543f1bfc3 |
@@ -14,11 +14,11 @@ jobs:
|
|||||||
at: ~/project
|
at: ~/project
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- v1-dependencies-{{ checksum "package.json" }}
|
- v1-dependencies-{{ checksum "yarn.lock" }}
|
||||||
- v1-dependencies-
|
- v1-dependencies-
|
||||||
- run: yarn install
|
- run: yarn install --frozen-lockfile
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: v1-dependencies-{{ checksum "package.json" }}
|
key: v1-dependencies-{{ checksum "yarn.lock" }}
|
||||||
paths: node_modules
|
paths: node_modules
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
root: .
|
root: .
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.8...@react-navigation/compat@5.0.0-alpha.9) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.7...@react-navigation/compat@5.0.0-alpha.8) (2019-10-15)
|
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.7...@react-navigation/compat@5.0.0-alpha.8) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/compat",
|
"name": "@react-navigation/compat",
|
||||||
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
||||||
"version": "5.0.0-alpha.8",
|
"version": "5.0.0-alpha.9",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export default function createCompatNavigatorFactory<
|
|||||||
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
||||||
order?: Array<Extract<keyof ParamList, string>>;
|
order?: Array<Extract<keyof ParamList, string>>;
|
||||||
defaultNavigationOptions?: ScreenOptions;
|
defaultNavigationOptions?: ScreenOptions;
|
||||||
navigationOptions?: { [key: string]: any };
|
navigationOptions?: Record<string, any>;
|
||||||
} = {}
|
} = {}
|
||||||
) => {
|
) => {
|
||||||
const Pair = createNavigator();
|
const Pair = createNavigator();
|
||||||
|
|||||||
@@ -3,6 +3,30 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.16...@react-navigation/core@5.0.0-alpha.17) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.15...@react-navigation/core@5.0.0-alpha.16) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rehydrate state before using it ([3e92e22](https://github.com/react-navigation/navigation-ex/commit/3e92e22))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* make it easier to navigate to a specific route in navigator ([#114](https://github.com/react-navigation/navigation-ex/issues/114)) ([a543f1b](https://github.com/react-navigation/navigation-ex/commit/a543f1b)), closes [#90](https://github.com/react-navigation/navigation-ex/issues/90)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.14...@react-navigation/core@5.0.0-alpha.15) (2019-10-15)
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.14...@react-navigation/core@5.0.0-alpha.15) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.15",
|
"version": "5.0.0-alpha.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -108,7 +108,24 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...state, index };
|
return {
|
||||||
|
...state,
|
||||||
|
index,
|
||||||
|
routes:
|
||||||
|
action.payload.params !== undefined
|
||||||
|
? state.routes.map((route, i) =>
|
||||||
|
i === index
|
||||||
|
? {
|
||||||
|
...route,
|
||||||
|
params: {
|
||||||
|
...route.params,
|
||||||
|
...action.payload.params,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: route
|
||||||
|
)
|
||||||
|
: state.routes,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import NavigationContainer from '../NavigationContainer';
|
|||||||
import useNavigationBuilder from '../useNavigationBuilder';
|
import useNavigationBuilder from '../useNavigationBuilder';
|
||||||
import useNavigation from '../useNavigation';
|
import useNavigation from '../useNavigation';
|
||||||
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
||||||
import { NavigationState } from '../types';
|
import { NavigationState, NavigationContainerRef } from '../types';
|
||||||
|
|
||||||
beforeEach(() => (MockRouterKey.current = 0));
|
beforeEach(() => (MockRouterKey.current = 0));
|
||||||
|
|
||||||
@@ -523,6 +523,80 @@ it('handles change in route names', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('navigates to nested child in a navigator', () => {
|
||||||
|
const TestNavigator = (props: any): any => {
|
||||||
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|
||||||
|
return descriptors[state.routes[state.index].key].render();
|
||||||
|
};
|
||||||
|
|
||||||
|
const TestComponent = ({ route }: any): any =>
|
||||||
|
`[${route.name}, ${JSON.stringify(route.params)}]`;
|
||||||
|
|
||||||
|
const onStateChange = jest.fn();
|
||||||
|
|
||||||
|
const navigation = React.createRef<NavigationContainerRef>();
|
||||||
|
|
||||||
|
const element = render(
|
||||||
|
<NavigationContainer ref={navigation} onStateChange={onStateChange}>
|
||||||
|
<TestNavigator>
|
||||||
|
<Screen name="foo">
|
||||||
|
{() => (
|
||||||
|
<TestNavigator>
|
||||||
|
<Screen name="foo-a" component={TestComponent} />
|
||||||
|
<Screen name="foo-b" component={TestComponent} />
|
||||||
|
</TestNavigator>
|
||||||
|
)}
|
||||||
|
</Screen>
|
||||||
|
<Screen name="bar">
|
||||||
|
{() => (
|
||||||
|
<TestNavigator initialRouteName="bar-a">
|
||||||
|
<Screen
|
||||||
|
name="bar-a"
|
||||||
|
component={TestComponent}
|
||||||
|
initialParams={{ lol: 'why' }}
|
||||||
|
/>
|
||||||
|
<Screen
|
||||||
|
name="bar-b"
|
||||||
|
component={TestComponent}
|
||||||
|
initialParams={{ some: 'stuff' }}
|
||||||
|
/>
|
||||||
|
</TestNavigator>
|
||||||
|
)}
|
||||||
|
</Screen>
|
||||||
|
</TestNavigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
|
||||||
|
|
||||||
|
act(
|
||||||
|
() =>
|
||||||
|
navigation.current &&
|
||||||
|
navigation.current.navigate('bar', {
|
||||||
|
screen: 'bar-b',
|
||||||
|
params: { test: 42 },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(
|
||||||
|
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"`
|
||||||
|
);
|
||||||
|
|
||||||
|
act(
|
||||||
|
() =>
|
||||||
|
navigation.current &&
|
||||||
|
navigation.current.navigate('bar', {
|
||||||
|
screen: 'bar-a',
|
||||||
|
params: { whoa: 'test' },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(
|
||||||
|
`"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('gives access to internal state', () => {
|
it('gives access to internal state', () => {
|
||||||
const TestNavigator = (props: any): any => {
|
const TestNavigator = (props: any): any => {
|
||||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { NavigationState, PartialState, Route } from './types';
|
|||||||
|
|
||||||
type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
|
type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
|
||||||
|
|
||||||
type StringifyConfig = { [key: string]: (value: any) => string };
|
type StringifyConfig = Record<string, (value: any) => string>;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
[routeName: string]: string | { path: string; stringify?: StringifyConfig };
|
[routeName: string]: string | { path: string; stringify?: StringifyConfig };
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import escape from 'escape-string-regexp';
|
|||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
import { NavigationState, PartialState } from './types';
|
import { NavigationState, PartialState } from './types';
|
||||||
|
|
||||||
type ParseConfig = { [key: string]: (value: string) => any };
|
type ParseConfig = Record<string, (value: string) => any>;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
[routeName: string]: string | { path: string; parse?: ParseConfig };
|
[routeName: string]: string | { path: string; parse?: ParseConfig };
|
||||||
@@ -78,7 +78,7 @@ export default function getStateFromPath(
|
|||||||
.filter(p => p.startsWith(':'));
|
.filter(p => p.startsWith(':'));
|
||||||
|
|
||||||
if (paramPatterns.length) {
|
if (paramPatterns.length) {
|
||||||
params = paramPatterns.reduce<{ [key: string]: any }>((acc, p, i) => {
|
params = paramPatterns.reduce<Record<string, any>>((acc, p, i) => {
|
||||||
const key = p.replace(/^:/, '');
|
const key = p.replace(/^:/, '');
|
||||||
const value = match[i + 1]; // The param segments start from index 1 in the regex match result
|
const value = match[i + 1]; // The param segments start from index 1 in the regex match result
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ export type Router<
|
|||||||
actionCreators?: ActionCreators<Action>;
|
actionCreators?: ActionCreators<Action>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ParamListBase = { [key: string]: object | undefined };
|
export type ParamListBase = Record<string, object | undefined>;
|
||||||
|
|
||||||
export type EventMapBase = {
|
export type EventMapBase = {
|
||||||
focus: undefined;
|
focus: undefined;
|
||||||
@@ -215,7 +215,7 @@ export type EventListenerCallback<EventName extends string, Data> = (
|
|||||||
e: EventArg<EventName, Data>
|
e: EventArg<EventName, Data>
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
export type EventConsumer<EventMap extends { [key: string]: any }> = {
|
export type EventConsumer<EventMap extends Record<string, any>> = {
|
||||||
/**
|
/**
|
||||||
* Subscribe to events from the parent navigator.
|
* Subscribe to events from the parent navigator.
|
||||||
*
|
*
|
||||||
@@ -232,7 +232,7 @@ export type EventConsumer<EventMap extends { [key: string]: any }> = {
|
|||||||
): void;
|
): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EventEmitter<EventMap extends { [key: string]: any }> = {
|
export type EventEmitter<EventMap extends Record<string, any>> = {
|
||||||
/**
|
/**
|
||||||
* Emit an event to child screens.
|
* Emit an event to child screens.
|
||||||
*
|
*
|
||||||
@@ -349,7 +349,7 @@ type NavigationHelpersCommon<
|
|||||||
|
|
||||||
export type NavigationHelpers<
|
export type NavigationHelpers<
|
||||||
ParamList extends ParamListBase,
|
ParamList extends ParamListBase,
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = NavigationHelpersCommon<ParamList> &
|
> = NavigationHelpersCommon<ParamList> &
|
||||||
EventEmitter<EventMap> & {
|
EventEmitter<EventMap> & {
|
||||||
/**
|
/**
|
||||||
@@ -376,7 +376,7 @@ export type NavigationProp<
|
|||||||
RouteName extends keyof ParamList = string,
|
RouteName extends keyof ParamList = string,
|
||||||
State extends NavigationState = NavigationState,
|
State extends NavigationState = NavigationState,
|
||||||
ScreenOptions extends object = {},
|
ScreenOptions extends object = {},
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = NavigationHelpersCommon<ParamList, State> & {
|
> = NavigationHelpersCommon<ParamList, State> & {
|
||||||
/**
|
/**
|
||||||
* Update the param object for the route.
|
* Update the param object for the route.
|
||||||
@@ -468,7 +468,7 @@ export type Descriptor<
|
|||||||
RouteName extends keyof ParamList = string,
|
RouteName extends keyof ParamList = string,
|
||||||
State extends NavigationState = NavigationState,
|
State extends NavigationState = NavigationState,
|
||||||
ScreenOptions extends object = {},
|
ScreenOptions extends object = {},
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = {
|
> = {
|
||||||
/**
|
/**
|
||||||
* Render the component associated with this route.
|
* Render the component associated with this route.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
|
|
||||||
type Options<State extends NavigationState, ScreenOptions extends object> = {
|
type Options<State extends NavigationState, ScreenOptions extends object> = {
|
||||||
state: State;
|
state: State;
|
||||||
screens: { [key: string]: RouteConfig<ParamListBase, string, ScreenOptions> };
|
screens: Record<string, RouteConfig<ParamListBase, string, ScreenOptions>>;
|
||||||
navigation: NavigationHelpers<ParamListBase>;
|
navigation: NavigationHelpers<ParamListBase>;
|
||||||
screenOptions?:
|
screenOptions?:
|
||||||
| ScreenOptions
|
| ScreenOptions
|
||||||
@@ -68,7 +68,7 @@ export default function useDescriptors<
|
|||||||
router,
|
router,
|
||||||
emitter,
|
emitter,
|
||||||
}: Options<State, ScreenOptions>) {
|
}: Options<State, ScreenOptions>) {
|
||||||
const [options, setOptions] = React.useState<{ [key: string]: object }>({});
|
const [options, setOptions] = React.useState<Record<string, object>>({});
|
||||||
const { trackAction } = React.useContext(NavigationBuilderContext);
|
const { trackAction } = React.useContext(NavigationBuilderContext);
|
||||||
|
|
||||||
const context = React.useMemo(
|
const context = React.useMemo(
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { EventEmitter, EventConsumer, EventArg } from './types';
|
import { EventEmitter, EventConsumer, EventArg } from './types';
|
||||||
|
|
||||||
export type NavigationEventEmitter = EventEmitter<{ [key: string]: any }> & {
|
export type NavigationEventEmitter = EventEmitter<Record<string, any>> & {
|
||||||
create: (target: string) => EventConsumer<{ [key: string]: any }>;
|
create: (target: string) => EventConsumer<Record<string, any>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Listeners = Array<(data: any) => void>;
|
type Listeners = Array<(data: any) => void>;
|
||||||
@@ -11,9 +11,7 @@ type Listeners = Array<(data: any) => void>;
|
|||||||
* Hook to manage the event system used by the navigator to notify screens of various events.
|
* Hook to manage the event system used by the navigator to notify screens of various events.
|
||||||
*/
|
*/
|
||||||
export default function useEventEmitter(): NavigationEventEmitter {
|
export default function useEventEmitter(): NavigationEventEmitter {
|
||||||
const listeners = React.useRef<{
|
const listeners = React.useRef<Record<string, Record<string, Listeners>>>({});
|
||||||
[key: string]: { [key: string]: Listeners };
|
|
||||||
}>({});
|
|
||||||
|
|
||||||
const create = React.useCallback((target: string) => {
|
const create = React.useCallback((target: string) => {
|
||||||
const removeListener = (type: string, callback: (data: any) => void) => {
|
const removeListener = (type: string, callback: (data: any) => void) => {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { NavigationStateContext } from './NavigationContainer';
|
import { NavigationStateContext } from './NavigationContainer';
|
||||||
|
import NavigationRouteContext from './NavigationRouteContext';
|
||||||
import Screen from './Screen';
|
import Screen from './Screen';
|
||||||
|
import { navigate } from './CommonActions';
|
||||||
import useEventEmitter from './useEventEmitter';
|
import useEventEmitter from './useEventEmitter';
|
||||||
import useRegisterNavigator from './useRegisterNavigator';
|
import useRegisterNavigator from './useRegisterNavigator';
|
||||||
import useDescriptors from './useDescriptors';
|
import useDescriptors from './useDescriptors';
|
||||||
@@ -30,6 +32,13 @@ import useOnGetState from './useOnGetState';
|
|||||||
// eslint-disable-next-line babel/no-unused-expressions
|
// eslint-disable-next-line babel/no-unused-expressions
|
||||||
PrivateValueStore;
|
PrivateValueStore;
|
||||||
|
|
||||||
|
type NavigatorRoute = {
|
||||||
|
params?: {
|
||||||
|
screen?: string;
|
||||||
|
params?: object;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two arrays with primitive values as the content.
|
* Compare two arrays with primitive values as the content.
|
||||||
* We need to make sure that both values and order match.
|
* We need to make sure that both values and order match.
|
||||||
@@ -89,39 +98,66 @@ export default function useNavigationBuilder<
|
|||||||
State extends NavigationState,
|
State extends NavigationState,
|
||||||
RouterOptions extends DefaultRouterOptions,
|
RouterOptions extends DefaultRouterOptions,
|
||||||
ScreenOptions extends object,
|
ScreenOptions extends object,
|
||||||
EventMap extends { [key: string]: any }
|
EventMap extends Record<string, any>
|
||||||
>(
|
>(
|
||||||
createRouter: RouterFactory<State, any, RouterOptions>,
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
||||||
options: DefaultNavigatorOptions<ScreenOptions> & RouterOptions
|
options: DefaultNavigatorOptions<ScreenOptions> & RouterOptions
|
||||||
) {
|
) {
|
||||||
useRegisterNavigator();
|
useRegisterNavigator();
|
||||||
|
|
||||||
|
const route = React.useContext(NavigationRouteContext) as (
|
||||||
|
| NavigatorRoute
|
||||||
|
| undefined);
|
||||||
|
|
||||||
|
const previousRouteRef = React.useRef(route);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
previousRouteRef.current = route;
|
||||||
|
}, [route]);
|
||||||
|
|
||||||
const { children, ...rest } = options;
|
const { children, ...rest } = options;
|
||||||
const { current: router } = React.useRef<Router<State, any>>(
|
const { current: router } = React.useRef<Router<State, any>>(
|
||||||
createRouter((rest as unknown) as RouterOptions)
|
createRouter({
|
||||||
|
...((rest as unknown) as RouterOptions),
|
||||||
|
...(route && route.params && typeof route.params.screen === 'string'
|
||||||
|
? { initialRouteName: route.params.screen }
|
||||||
|
: null),
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce(
|
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce<
|
||||||
(acc, curr) => {
|
Record<string, RouteConfig<ParamListBase, string, ScreenOptions>>
|
||||||
if (curr.name in acc) {
|
>((acc, curr) => {
|
||||||
throw new Error(
|
if (curr.name in acc) {
|
||||||
`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${curr.name}')`
|
throw new Error(
|
||||||
);
|
`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${curr.name}')`
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
acc[curr.name] = curr;
|
acc[curr.name] = curr;
|
||||||
return acc;
|
return acc;
|
||||||
},
|
}, {});
|
||||||
{} as { [key: string]: RouteConfig<ParamListBase, string, ScreenOptions> }
|
|
||||||
);
|
|
||||||
|
|
||||||
const routeNames = Object.keys(screens);
|
const routeNames = Object.keys(screens);
|
||||||
const routeParamList = routeNames.reduce(
|
const routeParamList = routeNames.reduce<Record<string, object | undefined>>(
|
||||||
(acc, curr) => {
|
(acc, curr) => {
|
||||||
acc[curr] = screens[curr].initialParams;
|
const { initialParams } = screens[curr];
|
||||||
|
const initialParamsFromParams =
|
||||||
|
route && route.params && route.params.screen === curr
|
||||||
|
? route.params.params
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
acc[curr] =
|
||||||
|
initialParams !== undefined || initialParamsFromParams !== undefined
|
||||||
|
? {
|
||||||
|
...initialParams,
|
||||||
|
...initialParamsFromParams,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: object | undefined }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!routeNames.length) {
|
if (!routeNames.length) {
|
||||||
@@ -175,28 +211,53 @@ export default function useNavigationBuilder<
|
|||||||
? (initializedStateRef.current as State)
|
? (initializedStateRef.current as State)
|
||||||
: (currentState as State);
|
: (currentState as State);
|
||||||
|
|
||||||
|
let nextState: State = state;
|
||||||
|
|
||||||
if (!isArrayEqual(state.routeNames, routeNames)) {
|
if (!isArrayEqual(state.routeNames, routeNames)) {
|
||||||
// When the list of route names change, the router should handle it to remove invalid routes
|
// When the list of route names change, the router should handle it to remove invalid routes
|
||||||
const nextState = router.getStateForRouteNamesChange(state, {
|
nextState = router.getStateForRouteNamesChange(state, {
|
||||||
routeNames,
|
routeNames,
|
||||||
routeParamList,
|
routeParamList,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (state !== nextState) {
|
|
||||||
// If the state needs to be updated, we'll schedule an update with React
|
|
||||||
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
|
||||||
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
|
||||||
performTransaction(() => {
|
|
||||||
setState(nextState);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The up-to-date state will come in next render, but we don't need to wait for it
|
|
||||||
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
|
||||||
// So we override the state objec we return to use the latest state as soon as possible
|
|
||||||
state = nextState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
previousRouteRef.current &&
|
||||||
|
route &&
|
||||||
|
route.params &&
|
||||||
|
typeof route.params.screen === 'string' &&
|
||||||
|
route.params !== previousRouteRef.current.params
|
||||||
|
) {
|
||||||
|
// If the route was updated with new name and/or params, we should navigate there
|
||||||
|
// The update should be limited to current navigator only, so we call the router manually
|
||||||
|
const updatedState = router.getStateForAction(
|
||||||
|
state,
|
||||||
|
navigate(route.params.screen, route.params.params)
|
||||||
|
);
|
||||||
|
|
||||||
|
nextState =
|
||||||
|
updatedState !== null
|
||||||
|
? router.getRehydratedState(updatedState, {
|
||||||
|
routeNames,
|
||||||
|
routeParamList,
|
||||||
|
})
|
||||||
|
: state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state !== nextState) {
|
||||||
|
// If the state needs to be updated, we'll schedule an update with React
|
||||||
|
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
||||||
|
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
||||||
|
performTransaction(() => {
|
||||||
|
setState(nextState);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The up-to-date state will come in next render, but we don't need to wait for it
|
||||||
|
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
||||||
|
// So we override the state objec we return to use the latest state as soon as possible
|
||||||
|
state = nextState;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
// We need to clean up state for this navigator on unmount
|
// We need to clean up state for this navigator on unmount
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type Options<State extends NavigationState> = {
|
|||||||
navigation: NavigationHelpers<ParamListBase> &
|
navigation: NavigationHelpers<ParamListBase> &
|
||||||
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
||||||
setOptions: (
|
setOptions: (
|
||||||
cb: (options: { [key: string]: object }) => { [key: string]: object }
|
cb: (options: Record<string, object>) => Record<string, object>
|
||||||
) => void;
|
) => void;
|
||||||
router: Router<State, NavigationAction>;
|
router: Router<State, NavigationAction>;
|
||||||
emitter: NavigationEventEmitter;
|
emitter: NavigationEventEmitter;
|
||||||
@@ -89,13 +89,13 @@ export default function useNavigationCache<
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpers = Object.keys(actions).reduce(
|
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
||||||
(acc, name) => {
|
(acc, name) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: () => void }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
acc[route.key] = {
|
acc[route.key] = {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|||||||
export default function useNavigationHelpers<
|
export default function useNavigationHelpers<
|
||||||
State extends NavigationState,
|
State extends NavigationState,
|
||||||
Action extends NavigationAction,
|
Action extends NavigationAction,
|
||||||
EventMap extends { [key: string]: any }
|
EventMap extends Record<string, any>
|
||||||
>({ onAction, getState, emitter, router }: Options<State, Action>) {
|
>({ onAction, getState, emitter, router }: Options<State, Action>) {
|
||||||
const resetRoot = React.useContext(ResetRootContext);
|
const resetRoot = React.useContext(ResetRootContext);
|
||||||
const parentNavigationHelpers = React.useContext(NavigationContext);
|
const parentNavigationHelpers = React.useContext(NavigationContext);
|
||||||
@@ -55,13 +55,13 @@ export default function useNavigationHelpers<
|
|||||||
...CommonActions,
|
...CommonActions,
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpers = Object.keys(actions).reduce(
|
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
||||||
(acc, name) => {
|
(acc, name) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: () => void }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.15...@react-navigation/drawer@5.0.0-alpha.16) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* navigation drawer sometimes not closing when pressed outside ([0d8cdc8](https://github.com/react-navigation/navigation-ex/commit/0d8cdc8))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.14...@react-navigation/drawer@5.0.0-alpha.15) (2019-10-17)
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.14...@react-navigation/drawer@5.0.0-alpha.15) (2019-10-17)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"drawer"
|
"drawer"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.15",
|
"version": "5.0.0-alpha.16",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"react-native-gesture-handler": "^1.3.0",
|
"react-native-gesture-handler": "^1.3.0",
|
||||||
"react-native-reanimated": "^1.3.0",
|
"react-native-reanimated": "^1.3.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^2.0.0-alpha.3",
|
"react-native-screens": "^2.0.0-alpha.5",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"react-native-gesture-handler": "^1.0.0",
|
"react-native-gesture-handler": "^1.0.0",
|
||||||
"react-native-reanimated": "^1.0.0",
|
"react-native-reanimated": "^1.0.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.3"
|
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -428,7 +428,14 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
x: this.touchX,
|
x: this.touchX,
|
||||||
translationX: this.gestureX,
|
translationX: this.gestureX,
|
||||||
velocityX: this.velocityX,
|
velocityX: this.velocityX,
|
||||||
state: this.gestureState,
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
private handleGestureStateChange = event([
|
||||||
|
{
|
||||||
|
nativeEvent: {
|
||||||
|
state: (s: Animated.Value<number>) => set(this.gestureState, s),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@@ -519,7 +526,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
||||||
failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
||||||
onGestureEvent={this.handleGestureEvent}
|
onGestureEvent={this.handleGestureEvent}
|
||||||
onHandlerStateChange={this.handleGestureEvent}
|
onHandlerStateChange={this.handleGestureStateChange}
|
||||||
hitSlop={hitSlop}
|
hitSlop={hitSlop}
|
||||||
enabled={!locked}
|
enabled={!locked}
|
||||||
{...gestureHandlerProps}
|
{...gestureHandlerProps}
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.14...@react-navigation/example@5.0.0-alpha.15) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.14](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.13...@react-navigation/example@5.0.0-alpha.14) (2019-10-17)
|
# [5.0.0-alpha.14](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.13...@react-navigation/example@5.0.0-alpha.14) (2019-10-17)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/example
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/example",
|
"name": "@react-navigation/example",
|
||||||
"description": "Demo app to showcase various functionality of React Navigation",
|
"description": "Demo app to showcase various functionality of React Navigation",
|
||||||
"version": "5.0.0-alpha.14",
|
"version": "5.0.0-alpha.15",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"nohoist": [
|
"nohoist": [
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"react-native-paper": "^3.0.0-alpha.7",
|
"react-native-paper": "^3.0.0-alpha.7",
|
||||||
"react-native-reanimated": "~1.2.0",
|
"react-native-reanimated": "~1.2.0",
|
||||||
"react-native-safe-area-context": "~0.3.6",
|
"react-native-safe-area-context": "~0.3.6",
|
||||||
"react-native-screens": "2.0.0-alpha.4",
|
"react-native-screens": "^2.0.0-alpha.5",
|
||||||
"react-native-tab-view": "2.10.0",
|
"react-native-tab-view": "2.10.0",
|
||||||
"react-native-unimodules": "^0.7.0-rc.1",
|
"react-native-unimodules": "^0.7.0-rc.1",
|
||||||
"react-native-web": "^0.11.7",
|
"react-native-web": "^0.11.7",
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.14...@react-navigation/material-bottom-tabs@5.0.0-alpha.15) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* navigation drawer sometimes not closing when pressed outside ([0d8cdc8](https://github.com/react-navigation/navigation-ex/commit/0d8cdc8))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.13...@react-navigation/material-bottom-tabs@5.0.0-alpha.14) (2019-10-17)
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.13...@react-navigation/material-bottom-tabs@5.0.0-alpha.14) (2019-10-17)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.14",
|
"version": "5.0.0-alpha.15",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
|||||||
target: state.key,
|
target: state.key,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
renderScene={({ route }) => descriptors[route.key].render()}
|
renderScene={({ route }: Scene) => descriptors[route.key].render()}
|
||||||
renderIcon={this.renderIcon}
|
renderIcon={this.renderIcon}
|
||||||
getLabelText={this.getLabelText}
|
getLabelText={this.getLabelText}
|
||||||
getColor={this.getColor}
|
getColor={this.getColor}
|
||||||
|
|||||||
@@ -3,6 +3,39 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.3...@react-navigation/native-stack@5.0.0-alpha.4) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **native-stack:** add support for large title attributes ([#135](https://github.com/react-navigation/navigation-ex/issues/135)) ([6cf1a04](https://github.com/react-navigation/navigation-ex/commit/6cf1a04))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.3](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.2...@react-navigation/native-stack@5.0.0-alpha.3) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove top margin when header is hidden in native stack. fixes [#131](https://github.com/react-navigation/navigation-ex/issues/131) ([fb726ee](https://github.com/react-navigation/navigation-ex/commit/fb726ee))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.2](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.1...@react-navigation/native-stack@5.0.0-alpha.2) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix header font size config in native stack ([#128](https://github.com/react-navigation/navigation-ex/issues/128)) ([477c088](https://github.com/react-navigation/navigation-ex/commit/477c088))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 5.0.0-alpha.1 (2019-10-15)
|
# 5.0.0-alpha.1 (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.1",
|
"version": "5.0.0-alpha.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,14 +34,14 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"del-cli": "^2.0.0",
|
"del-cli": "^2.0.0",
|
||||||
"react-native-screens": "^2.0.0-alpha.3",
|
"react-native-screens": "^2.0.0-alpha.5",
|
||||||
"typescript": "^3.5.3"
|
"typescript": "^3.5.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-screens": "^2.0.0-alpha.3"
|
"react-native-screens": "^2.0.0-alpha.5"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -123,6 +123,19 @@ export type NativeStackNavigationOptions = {
|
|||||||
fontSize?: number;
|
fontSize?: number;
|
||||||
color?: string;
|
color?: string;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Style object for header large title. Supported properties:
|
||||||
|
* - fontFamily
|
||||||
|
* - fontSize
|
||||||
|
*
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerLargeTitleStyle?: {
|
||||||
|
fontFamily?: string;
|
||||||
|
fontSize?: number;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Style object for header back title. Supported properties:
|
* Style object for header back title. Supported properties:
|
||||||
* - fontFamily
|
* - fontFamily
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export default function HeaderConfig(props: Props) {
|
|||||||
headerTranslucent,
|
headerTranslucent,
|
||||||
headerStyle = {},
|
headerStyle = {},
|
||||||
headerTitleStyle = {},
|
headerTitleStyle = {},
|
||||||
|
headerLargeTitleStyle = {},
|
||||||
headerBackTitleStyle = {},
|
headerBackTitleStyle = {},
|
||||||
headerShown,
|
headerShown,
|
||||||
gestureEnabled,
|
gestureEnabled,
|
||||||
@@ -46,7 +47,7 @@ export default function HeaderConfig(props: Props) {
|
|||||||
: route.name
|
: route.name
|
||||||
}
|
}
|
||||||
titleFontFamily={headerTitleStyle.fontFamily}
|
titleFontFamily={headerTitleStyle.fontFamily}
|
||||||
titleFontSize={headerTitleStyle.fontFamily}
|
titleFontSize={headerTitleStyle.fontSize}
|
||||||
titleColor={
|
titleColor={
|
||||||
headerTitleStyle.color !== undefined
|
headerTitleStyle.color !== undefined
|
||||||
? headerTitleStyle.color
|
? headerTitleStyle.color
|
||||||
@@ -58,6 +59,8 @@ export default function HeaderConfig(props: Props) {
|
|||||||
color={headerTintColor}
|
color={headerTintColor}
|
||||||
gestureEnabled={gestureEnabled === undefined ? true : gestureEnabled}
|
gestureEnabled={gestureEnabled === undefined ? true : gestureEnabled}
|
||||||
largeTitle={headerLargeTitle}
|
largeTitle={headerLargeTitle}
|
||||||
|
largeTitleFontFamily={headerLargeTitleStyle.fontFamily}
|
||||||
|
largeTitleFontSize={headerLargeTitleStyle.fontSize}
|
||||||
backgroundColor={headerStyle.backgroundColor}
|
backgroundColor={headerStyle.backgroundColor}
|
||||||
>
|
>
|
||||||
{headerRight !== undefined ? (
|
{headerRight !== undefined ? (
|
||||||
|
|||||||
@@ -43,7 +43,20 @@ export default function StackView({ state, navigation, descriptors }: Props) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<HeaderConfig {...options} route={route} />
|
<HeaderConfig {...options} route={route} />
|
||||||
<View style={[styles.content, contentStyle]}>{renderScene()}</View>
|
<View
|
||||||
|
style={[
|
||||||
|
styles.content,
|
||||||
|
{
|
||||||
|
marginTop:
|
||||||
|
Platform.OS === 'android' && options.headerShown !== false
|
||||||
|
? 56
|
||||||
|
: 0,
|
||||||
|
},
|
||||||
|
contentStyle,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{renderScene()}
|
||||||
|
</View>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -55,7 +68,6 @@ const styles = StyleSheet.create({
|
|||||||
content: {
|
content: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: '#eee',
|
backgroundColor: '#eee',
|
||||||
marginTop: Platform.OS === 'android' ? 56 : 0,
|
|
||||||
},
|
},
|
||||||
scenes: {
|
scenes: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
@@ -3,6 +3,14 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.12...@react-navigation/native@5.0.0-alpha.13) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.11...@react-navigation/native@5.0.0-alpha.12) (2019-10-15)
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.11...@react-navigation/native@5.0.0-alpha.12) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"ios",
|
"ios",
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.12",
|
"version": "5.0.0-alpha.13",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
type Config = {
|
type Config = {
|
||||||
[routeName: string]:
|
[routeName: string]:
|
||||||
| string
|
| string
|
||||||
| { path: string; parse?: { [key: string]: (value: string) => any } };
|
| { path: string; parse?: Record<string, (value: string) => any> };
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
|
|||||||
@@ -3,6 +3,29 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.27...@react-navigation/stack@5.0.0-alpha.28) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't fire onOpen when screen is unmounting ([#137](https://github.com/react-navigation/navigation-ex/issues/137)) ([f22abb7](https://github.com/react-navigation/navigation-ex/commit/f22abb7)), closes [#136](https://github.com/react-navigation/navigation-ex/issues/136)
|
||||||
|
* don't keep unfocused header backgrounds visible ([031c4d2](https://github.com/react-navigation/navigation-ex/commit/031c4d2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.26...@react-navigation/stack@5.0.0-alpha.27) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add an option to override safe area insets ([300791a](https://github.com/react-navigation/navigation-ex/commit/300791a))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.25...@react-navigation/stack@5.0.0-alpha.26) (2019-10-17)
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.25...@react-navigation/stack@5.0.0-alpha.26) (2019-10-17)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"stack"
|
"stack"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.26",
|
"version": "5.0.0-alpha.28",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"react-native-gesture-handler": "^1.3.0",
|
"react-native-gesture-handler": "^1.3.0",
|
||||||
"react-native-reanimated": "^1.3.0",
|
"react-native-reanimated": "^1.3.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^2.0.0-alpha.3",
|
"react-native-screens": "^2.0.0-alpha.5",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
"react-native-gesture-handler": "^1.0.0",
|
"react-native-gesture-handler": "^1.0.0",
|
||||||
"react-native-reanimated": "^1.0.0",
|
"react-native-reanimated": "^1.0.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.3"
|
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ export function forFade({
|
|||||||
leftButtonStyle: { opacity },
|
leftButtonStyle: { opacity },
|
||||||
rightButtonStyle: { opacity },
|
rightButtonStyle: { opacity },
|
||||||
titleStyle: { opacity },
|
titleStyle: { opacity },
|
||||||
backgroundStyle: { opacity: current.progress },
|
backgroundStyle: {
|
||||||
|
opacity: interpolate(progress, {
|
||||||
|
inputRange: [0, 1, 1.9, 2],
|
||||||
|
outputRange: [0, 1, 1, 0],
|
||||||
|
}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
LayoutChangeEvent,
|
LayoutChangeEvent,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import Animated from 'react-native-reanimated';
|
import Animated from 'react-native-reanimated';
|
||||||
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||||
import {
|
import {
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
@@ -207,6 +208,10 @@ export type StackHeaderProps = {
|
|||||||
* Layout of the screen.
|
* Layout of the screen.
|
||||||
*/
|
*/
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
|
/**
|
||||||
|
* Safe area insets to use in the header, e.g. to apply extra spacing for statusbar and notch.
|
||||||
|
*/
|
||||||
|
insets: EdgeInsets;
|
||||||
/**
|
/**
|
||||||
* Object representing the current scene, such as the route object and animation progress.
|
* Object representing the current scene, such as the route object and animation progress.
|
||||||
*/
|
*/
|
||||||
@@ -302,6 +307,17 @@ export type StackNavigationOptions = StackHeaderOptions &
|
|||||||
* Defaults to 0.3.
|
* Defaults to 0.3.
|
||||||
*/
|
*/
|
||||||
gestureVelocityImpact?: number;
|
gestureVelocityImpact?: number;
|
||||||
|
/**
|
||||||
|
* Safe area insets for the screen. This is used to avoid elements like notch and status bar.
|
||||||
|
* By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
|
||||||
|
* For example, to remove the extra spacing for status bar, pass `safeAreaInsets: { top: 0 }`.
|
||||||
|
*/
|
||||||
|
safeAreaInsets?: {
|
||||||
|
top?: number;
|
||||||
|
right?: number;
|
||||||
|
bottom?: number;
|
||||||
|
left?: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StackNavigationConfig = {
|
export type StackNavigationConfig = {
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { StackActions } from '@react-navigation/routers';
|
import { StackActions } from '@react-navigation/routers';
|
||||||
import { useSafeArea } from 'react-native-safe-area-context';
|
|
||||||
|
|
||||||
import HeaderSegment from './HeaderSegment';
|
import HeaderSegment from './HeaderSegment';
|
||||||
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
||||||
import HeaderTitle from './HeaderTitle';
|
import HeaderTitle from './HeaderTitle';
|
||||||
|
|
||||||
export default React.memo(function Header(props: StackHeaderProps) {
|
export default React.memo(function Header(props: StackHeaderProps) {
|
||||||
const insets = useSafeArea();
|
const {
|
||||||
|
scene,
|
||||||
const { scene, previous, layout, navigation, styleInterpolator } = props;
|
previous,
|
||||||
|
layout,
|
||||||
|
insets,
|
||||||
|
navigation,
|
||||||
|
styleInterpolator,
|
||||||
|
} = props;
|
||||||
const { options } = scene.descriptor;
|
const { options } = scene.descriptor;
|
||||||
const title =
|
const title =
|
||||||
typeof options.headerTitle !== 'function' &&
|
typeof options.headerTitle !== 'function' &&
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
ParamListBase,
|
ParamListBase,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import { StackNavigationState } from '@react-navigation/routers';
|
import { StackNavigationState } from '@react-navigation/routers';
|
||||||
|
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
import { forStatic } from '../../TransitionConfigs/HeaderStyleInterpolators';
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
export type Props = {
|
export type Props = {
|
||||||
mode: 'float' | 'screen';
|
mode: 'float' | 'screen';
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
|
insets: EdgeInsets;
|
||||||
scenes: Array<Scene<Route<string>> | undefined>;
|
scenes: Array<Scene<Route<string>> | undefined>;
|
||||||
state: StackNavigationState;
|
state: StackNavigationState;
|
||||||
getPreviousRoute: (props: {
|
getPreviousRoute: (props: {
|
||||||
@@ -36,6 +38,7 @@ export default function HeaderContainer({
|
|||||||
mode,
|
mode,
|
||||||
scenes,
|
scenes,
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
onContentHeightChange,
|
onContentHeightChange,
|
||||||
@@ -87,6 +90,7 @@ export default function HeaderContainer({
|
|||||||
const props = {
|
const props = {
|
||||||
mode,
|
mode,
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
scene,
|
scene,
|
||||||
previous,
|
previous,
|
||||||
navigation: scene.descriptor.navigation as StackNavigationProp<
|
navigation: scene.descriptor.navigation as StackNavigationProp<
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type State = {
|
|||||||
leftLabelLayout?: Layout;
|
leftLabelLayout?: Layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
const warnIfHeaderStylesDefined = (styles: { [key: string]: any }) => {
|
const warnIfHeaderStylesDefined = (styles: Record<string, any>) => {
|
||||||
Object.keys(styles).forEach(styleProp => {
|
Object.keys(styles).forEach(styleProp => {
|
||||||
const value = styles[styleProp];
|
const value = styles[styleProp];
|
||||||
|
|
||||||
|
|||||||
@@ -281,19 +281,11 @@ export default class Card extends React.Component<Props> {
|
|||||||
// during running. However, we need to invoke listener onClose
|
// during running. However, we need to invoke listener onClose
|
||||||
// manually in this case
|
// manually in this case
|
||||||
if (this.isRunningAnimation || this.noAnimationStartedSoFar) {
|
if (this.isRunningAnimation || this.noAnimationStartedSoFar) {
|
||||||
if (this.isVisibleValue) {
|
this.props.onClose(false);
|
||||||
this.props.onOpen(false);
|
|
||||||
} else {
|
|
||||||
this.props.onClose(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private isVisible = new Value<Binary>(TRUE);
|
private isVisible = new Value<Binary>(TRUE);
|
||||||
private gestureVelocityImpact = new Value<number>(
|
|
||||||
this.props.gestureVelocityImpact
|
|
||||||
);
|
|
||||||
private isVisibleValue: Binary = TRUE;
|
|
||||||
private nextIsVisible = new Value<Binary | -1>(UNSET);
|
private nextIsVisible = new Value<Binary | -1>(UNSET);
|
||||||
|
|
||||||
private isClosing = new Value<Binary>(FALSE);
|
private isClosing = new Value<Binary>(FALSE);
|
||||||
@@ -313,7 +305,11 @@ export default class Card extends React.Component<Props> {
|
|||||||
height: new Value(this.props.layout.height),
|
height: new Value(this.props.layout.height),
|
||||||
};
|
};
|
||||||
|
|
||||||
openingSpecConfig =
|
private gestureVelocityImpact = new Value<number>(
|
||||||
|
this.props.gestureVelocityImpact
|
||||||
|
);
|
||||||
|
|
||||||
|
private openingSpecConfig =
|
||||||
this.props.transitionSpec.open.animation === 'timing'
|
this.props.transitionSpec.open.animation === 'timing'
|
||||||
? transformTimingConfigToAnimatedValues(
|
? transformTimingConfigToAnimatedValues(
|
||||||
this.props.transitionSpec.open.config
|
this.props.transitionSpec.open.config
|
||||||
@@ -322,7 +318,7 @@ export default class Card extends React.Component<Props> {
|
|||||||
this.props.transitionSpec.open.config
|
this.props.transitionSpec.open.config
|
||||||
);
|
);
|
||||||
|
|
||||||
closingSpecConfig =
|
private closingSpecConfig =
|
||||||
this.props.transitionSpec.close.animation === 'timing'
|
this.props.transitionSpec.close.animation === 'timing'
|
||||||
? transformTimingConfigToAnimatedValues(
|
? transformTimingConfigToAnimatedValues(
|
||||||
this.props.transitionSpec.close.config
|
this.props.transitionSpec.close.config
|
||||||
@@ -385,7 +381,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
this.props.current,
|
this.props.current,
|
||||||
this.props.next,
|
this.props.next,
|
||||||
this.props.layout,
|
this.props.layout,
|
||||||
this.props.insets
|
this.props.insets.top,
|
||||||
|
this.props.insets.right,
|
||||||
|
this.props.insets.bottom,
|
||||||
|
this.props.insets.left
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -530,19 +529,9 @@ export default class Card extends React.Component<Props> {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
private changeVisiblityExec = onChange(
|
|
||||||
this.isVisible,
|
|
||||||
call([this.isVisible], ([isVisible]) => (this.isVisibleValue = isVisible))
|
|
||||||
);
|
|
||||||
|
|
||||||
private execNoGesture = block([
|
private execNoGesture = block([
|
||||||
...this.exec,
|
...this.exec,
|
||||||
this.runTransition(this.isVisible),
|
this.runTransition(this.isVisible),
|
||||||
onChange(
|
|
||||||
this.isVisible,
|
|
||||||
call([this.isVisible], ([isVisible]) => (this.isVisibleValue = isVisible))
|
|
||||||
),
|
|
||||||
this.changeVisiblityExec,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private execWithGesture = block([
|
private execWithGesture = block([
|
||||||
@@ -651,7 +640,6 @@ export default class Card extends React.Component<Props> {
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
this.changeVisiblityExec,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private handleGestureEventHorizontal = Animated.event([
|
private handleGestureEventHorizontal = Animated.event([
|
||||||
@@ -684,7 +672,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
current: Animated.Node<number>,
|
current: Animated.Node<number>,
|
||||||
next: Animated.Node<number> | undefined,
|
next: Animated.Node<number> | undefined,
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
insets: EdgeInsets
|
insetTop: number,
|
||||||
|
insetRight: number,
|
||||||
|
insetBottom: number,
|
||||||
|
insetLeft: number
|
||||||
) =>
|
) =>
|
||||||
styleInterpolator({
|
styleInterpolator({
|
||||||
index,
|
index,
|
||||||
@@ -694,7 +685,12 @@ export default class Card extends React.Component<Props> {
|
|||||||
layouts: {
|
layouts: {
|
||||||
screen: layout,
|
screen: layout,
|
||||||
},
|
},
|
||||||
insets,
|
insets: {
|
||||||
|
top: insetTop,
|
||||||
|
right: insetRight,
|
||||||
|
bottom: insetBottom,
|
||||||
|
left: insetLeft,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -708,7 +704,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
this.props.current,
|
this.props.current,
|
||||||
this.props.next,
|
this.props.next,
|
||||||
this.props.layout,
|
this.props.layout,
|
||||||
this.props.insets
|
this.props.insets.top,
|
||||||
|
this.props.insets.right,
|
||||||
|
this.props.insets.bottom,
|
||||||
|
this.props.insets.left
|
||||||
);
|
);
|
||||||
|
|
||||||
private gestureActivationCriteria() {
|
private gestureActivationCriteria() {
|
||||||
@@ -776,7 +775,10 @@ export default class Card extends React.Component<Props> {
|
|||||||
current,
|
current,
|
||||||
next,
|
next,
|
||||||
layout,
|
layout,
|
||||||
insets
|
insets.top,
|
||||||
|
insets.right,
|
||||||
|
insets.bottom,
|
||||||
|
insets.left
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ type State = {
|
|||||||
scenes: Scene<Route<string>>[];
|
scenes: Scene<Route<string>>[];
|
||||||
progress: ProgressValues;
|
progress: ProgressValues;
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
floatingHeaderHeights: { [key: string]: number };
|
floatingHeaderHeights: Record<string, number>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const dimensions = Dimensions.get('window');
|
const dimensions = Dimensions.get('window');
|
||||||
@@ -119,23 +119,20 @@ const getFloatingHeaderHeights = (
|
|||||||
insets: EdgeInsets,
|
insets: EdgeInsets,
|
||||||
descriptors: StackDescriptorMap,
|
descriptors: StackDescriptorMap,
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
previous: { [key: string]: number }
|
previous: Record<string, number>
|
||||||
) => {
|
) => {
|
||||||
const defaultHeaderHeight = getDefaultHeaderHeight(layout, insets);
|
const defaultHeaderHeight = getDefaultHeaderHeight(layout, insets);
|
||||||
|
|
||||||
return routes.reduce(
|
return routes.reduce<Record<string, number>>((acc, curr) => {
|
||||||
(acc, curr) => {
|
const { options = {} } = descriptors[curr.key] || {};
|
||||||
const { options = {} } = descriptors[curr.key] || {};
|
const { height = previous[curr.key] } = StyleSheet.flatten(
|
||||||
const { height = previous[curr.key] } = StyleSheet.flatten(
|
options.headerStyle || {}
|
||||||
options.headerStyle || {}
|
);
|
||||||
);
|
|
||||||
|
|
||||||
acc[curr.key] = typeof height === 'number' ? height : defaultHeaderHeight;
|
acc[curr.key] = typeof height === 'number' ? height : defaultHeaderHeight;
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
}, {});
|
||||||
{} as { [key: string]: number }
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class Stack extends React.Component<Props, State> {
|
export default class Stack extends React.Component<Props, State> {
|
||||||
@@ -332,6 +329,13 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
top = insets.top,
|
||||||
|
right = insets.right,
|
||||||
|
bottom = insets.bottom,
|
||||||
|
left = insets.left,
|
||||||
|
} = focusedOptions.safeAreaInsets || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<MaybeScreenContainer
|
<MaybeScreenContainer
|
||||||
@@ -358,6 +362,7 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
safeAreaInsets,
|
||||||
headerShown,
|
headerShown,
|
||||||
headerTransparent,
|
headerTransparent,
|
||||||
cardTransparent,
|
cardTransparent,
|
||||||
@@ -406,6 +411,13 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
top: safeAreaInsetTop = insets.top,
|
||||||
|
right: safeAreaInsetRight = insets.right,
|
||||||
|
bottom: safeAreaInsetBottom = insets.bottom,
|
||||||
|
left: safeAreaInsetLeft = insets.left,
|
||||||
|
} = safeAreaInsets || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MaybeScreen
|
<MaybeScreen
|
||||||
key={route.key}
|
key={route.key}
|
||||||
@@ -420,12 +432,15 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
focused={focused}
|
focused={focused}
|
||||||
closing={closingRouteKeys.includes(route.key)}
|
closing={closingRouteKeys.includes(route.key)}
|
||||||
layout={layout}
|
layout={layout}
|
||||||
insets={insets}
|
|
||||||
current={current}
|
current={current}
|
||||||
scene={scene}
|
scene={scene}
|
||||||
previousScene={scenes[index - 1]}
|
previousScene={scenes[index - 1]}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
state={state}
|
state={state}
|
||||||
|
safeAreaInsetTop={safeAreaInsetTop}
|
||||||
|
safeAreaInsetRight={safeAreaInsetRight}
|
||||||
|
safeAreaInsetBottom={safeAreaInsetBottom}
|
||||||
|
safeAreaInsetLeft={safeAreaInsetLeft}
|
||||||
cardTransparent={cardTransparent}
|
cardTransparent={cardTransparent}
|
||||||
cardOverlayEnabled={cardOverlayEnabled}
|
cardOverlayEnabled={cardOverlayEnabled}
|
||||||
cardShadowEnabled={cardShadowEnabled}
|
cardShadowEnabled={cardShadowEnabled}
|
||||||
@@ -459,6 +474,7 @@ export default class Stack extends React.Component<Props, State> {
|
|||||||
? renderHeader({
|
? renderHeader({
|
||||||
mode: 'float',
|
mode: 'float',
|
||||||
layout,
|
layout,
|
||||||
|
insets: { top, right, bottom, left },
|
||||||
scenes,
|
scenes,
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||||
import Animated from 'react-native-reanimated';
|
import Animated from 'react-native-reanimated';
|
||||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
||||||
import { StackNavigationState } from '@react-navigation/routers';
|
import { StackNavigationState } from '@react-navigation/routers';
|
||||||
import { Route } from '@react-navigation/core';
|
import { Route } from '@react-navigation/core';
|
||||||
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
||||||
@@ -20,12 +19,15 @@ type Props = TransitionPreset & {
|
|||||||
focused: boolean;
|
focused: boolean;
|
||||||
closing: boolean;
|
closing: boolean;
|
||||||
layout: Layout;
|
layout: Layout;
|
||||||
insets: EdgeInsets;
|
|
||||||
current: Animated.Value<number>;
|
current: Animated.Value<number>;
|
||||||
previousScene?: Scene<Route<string>>;
|
previousScene?: Scene<Route<string>>;
|
||||||
scene: Scene<Route<string>>;
|
scene: Scene<Route<string>>;
|
||||||
state: StackNavigationState;
|
state: StackNavigationState;
|
||||||
navigation: StackNavigationHelpers;
|
navigation: StackNavigationHelpers;
|
||||||
|
safeAreaInsetTop: number;
|
||||||
|
safeAreaInsetRight: number;
|
||||||
|
safeAreaInsetBottom: number;
|
||||||
|
safeAreaInsetLeft: number;
|
||||||
cardTransparent?: boolean;
|
cardTransparent?: boolean;
|
||||||
cardOverlayEnabled?: boolean;
|
cardOverlayEnabled?: boolean;
|
||||||
cardShadowEnabled?: boolean;
|
cardShadowEnabled?: boolean;
|
||||||
@@ -96,7 +98,6 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
const {
|
const {
|
||||||
index,
|
index,
|
||||||
layout,
|
layout,
|
||||||
insets,
|
|
||||||
active,
|
active,
|
||||||
focused,
|
focused,
|
||||||
closing,
|
closing,
|
||||||
@@ -104,6 +105,10 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
state,
|
state,
|
||||||
scene,
|
scene,
|
||||||
previousScene,
|
previousScene,
|
||||||
|
safeAreaInsetTop,
|
||||||
|
safeAreaInsetRight,
|
||||||
|
safeAreaInsetBottom,
|
||||||
|
safeAreaInsetLeft,
|
||||||
cardTransparent,
|
cardTransparent,
|
||||||
cardOverlayEnabled,
|
cardOverlayEnabled,
|
||||||
cardShadowEnabled,
|
cardShadowEnabled,
|
||||||
@@ -126,6 +131,13 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
headerStyleInterpolator,
|
headerStyleInterpolator,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const insets = {
|
||||||
|
top: safeAreaInsetTop,
|
||||||
|
right: safeAreaInsetRight,
|
||||||
|
bottom: safeAreaInsetBottom,
|
||||||
|
left: safeAreaInsetLeft,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
index={index}
|
index={index}
|
||||||
@@ -168,6 +180,7 @@ export default class StackItem extends React.PureComponent<Props> {
|
|||||||
? renderHeader({
|
? renderHeader({
|
||||||
mode: 'screen',
|
mode: 'screen',
|
||||||
layout,
|
layout,
|
||||||
|
insets,
|
||||||
scenes: [previousScene, scene],
|
scenes: [previousScene, scene],
|
||||||
state,
|
state,
|
||||||
getPreviousRoute,
|
getPreviousRoute,
|
||||||
|
|||||||
15
yarn.lock
15
yarn.lock
@@ -13133,17 +13133,10 @@ react-native-safe-area-view@^0.12.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
hoist-non-react-statics "^2.3.1"
|
hoist-non-react-statics "^2.3.1"
|
||||||
|
|
||||||
react-native-screens@2.0.0-alpha.4:
|
react-native-screens@^2.0.0-alpha.5:
|
||||||
version "2.0.0-alpha.4"
|
version "2.0.0-alpha.5"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-2.0.0-alpha.4.tgz#cf869bba2a5940f0b71d1dde9cf4e545cc0e97d0"
|
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-2.0.0-alpha.5.tgz#5b6a72df959d31ffaf7045cd5eb753477e80689b"
|
||||||
integrity sha512-/MdbyDwmvGncnyH4TVPB4JAawtGVZtyG5NOAbJ14wVmsRZhOqVABmiRP7jGO9tKOCENnoVDKspEw24u66G7EMw==
|
integrity sha512-uKVc+JYEC59Dz2RPBI4tnaIB8W6T0dHGY6PjUtvkvaBmZBjfxhpezd3m2t8o913Xarx6EvT2maSH8816+MNJnw==
|
||||||
dependencies:
|
|
||||||
debounce "^1.2.0"
|
|
||||||
|
|
||||||
react-native-screens@^2.0.0-alpha.3:
|
|
||||||
version "2.0.0-alpha.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-2.0.0-alpha.3.tgz#af86f265b2fb4293b626cf4396db7743de5a54af"
|
|
||||||
integrity sha512-SA3uGrc3UM1V9y6gfVU1UPf1a3dMyQCj3p5J7y6g81Of8rV5Pc34s6fWzOKNAWgOiviAktZB1z7Jngdl7+acZg==
|
|
||||||
dependencies:
|
dependencies:
|
||||||
debounce "^1.2.0"
|
debounce "^1.2.0"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user