chore: update prettier

This commit is contained in:
Satyajit Sahoo
2020-03-23 00:02:47 +01:00
parent 911d6bb2f4
commit a929933bde
58 changed files with 197 additions and 183 deletions

View File

@@ -30,7 +30,7 @@ function createStackNavigator(
return createNavigator(
// TODO: don't have time to fix it right now
// @ts-ignore
navigatorProps => <StackView {...navigatorProps} />,
(navigatorProps) => <StackView {...navigatorProps} />,
router,
stackConfig
);

View File

@@ -58,7 +58,7 @@ export default function validateDeprecatedConfig(
) {
let result = options;
Object.keys(validations).forEach(name => {
Object.keys(validations).forEach((name) => {
if (name in config) {
const { compat, message } = validations[name];

View File

@@ -12,10 +12,10 @@ const shownWarnings: string[] = [];
const validations: Validation[] = [
{
check: o => typeof o.headerForceInset === 'object',
check: (o) => typeof o.headerForceInset === 'object',
deprecated: 'headerForceInset',
updated: 'safeAreaInsets',
compat: o => {
compat: (o) => {
const { headerForceInset, ...rest } = o;
let safeAreaInsets: Partial<EdgeInsets> | undefined = {
@@ -55,20 +55,20 @@ const validations: Validation[] = [
},
},
{
check: o => o.gesturesEnabled !== undefined,
check: (o) => o.gesturesEnabled !== undefined,
deprecated: 'gesturesEnabled',
updated: 'gestureEnabled',
compat: o => {
compat: (o) => {
const { gesturesEnabled, ...rest } = o;
return { ...rest, gestureEnabled: gesturesEnabled };
},
},
{
check: o => o.header === null,
check: (o) => o.header === null,
deprecated: 'header: null',
updated: 'headerShown: false',
compat: o => {
compat: (o) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { header, ...rest } = o;
@@ -76,26 +76,26 @@ const validations: Validation[] = [
},
},
{
check: o => o.header != null && typeof o.header !== 'function',
check: (o) => o.header != null && typeof o.header !== 'function',
deprecated: 'header: <SomeElement />',
updated: 'header: () => <SomeElement />',
compat: o => ({ ...o, header: () => o.header }),
compat: (o) => ({ ...o, header: () => o.header }),
},
{
check: o =>
check: (o) =>
o.headerTitle !== undefined &&
typeof o.headerTitle !== 'string' &&
typeof o.headerTitle !== 'function',
deprecated: 'headerTitle: <SomeElement />',
updated: 'headerTitle: () => <SomeElement />',
compat: o => ({ ...o, headerTitle: () => o.headerTitle }),
compat: (o) => ({ ...o, headerTitle: () => o.headerTitle }),
},
...['headerLeft', 'headerRight', 'headerBackground', 'headerBackImage'].map(
(p): Validation => ({
check: (o: any) => o[p] !== undefined && typeof o[p] !== 'function',
deprecated: `${p}: <SomeElement />`,
updated: `${p}: () => <SomeElement />`,
compat: o => ({ ...o, [p]: () => o[p] }),
compat: (o) => ({ ...o, [p]: () => o[p] }),
})
),
];
@@ -108,7 +108,7 @@ export default function validateDeprecatedOptions(
const warnings: Validation[] = [];
// Validate options to show warnings for deprecations
validations.forEach(v => {
validations.forEach((v) => {
if (v.check(options)) {
result = v.compat(result);
@@ -127,7 +127,7 @@ export default function validateDeprecatedOptions(
console.warn(
`Deprecation in 'navigationOptions':\n${warnings
.map(
v =>
(v) =>
`- '${v.deprecated}' will be removed in a future version. Use '${v.updated}' instead`
)
.join('\n')}`

View File

@@ -4,7 +4,7 @@ export default function debounce<T extends (...args: any[]) => void>(
): T {
let timeout: NodeJS.Timeout | number | undefined;
return function(this: any, ...args) {
return function (this: any, ...args) {
if (!timeout) {
// eslint-disable-next-line babel/no-invalid-this
func.apply(this, args);

View File

@@ -118,7 +118,7 @@ export default function HeaderContainer({
<View
onLayout={
onContentHeightChange
? e =>
? (e) =>
onContentHeightChange({
route: scene.route,
height: e.nativeEvent.layout.height,

View File

@@ -38,7 +38,7 @@ type State = {
};
const warnIfHeaderStylesDefined = (styles: Record<string, any>) => {
Object.keys(styles).forEach(styleProp => {
Object.keys(styles).forEach((styleProp) => {
const value = styles[styleProp];
if (styleProp === 'position' && value === 'absolute') {

View File

@@ -30,7 +30,7 @@ type Props = {
export default function SafeAreaProviderCompat({ children }: Props) {
return (
<SafeAreaConsumer>
{insets => {
{(insets) => {
if (insets) {
// If we already have insets, don't wrap the stack in another safe area provider
// This avoids an issue with updates at the cost of potentially incorrect values

View File

@@ -117,7 +117,7 @@ export default class StackView extends React.Component<Props, State> {
// We only need to animate routes if the focused route changed
// Animating previous routes won't be visible coz the focused route is on top of everything
if (!previousRoutes.find(r => r.key === nextFocusedRoute.key)) {
if (!previousRoutes.find((r) => r.key === nextFocusedRoute.key)) {
// A new route has come to the focus, we treat this as a push
// A replace can also trigger this, the animation should look like push
@@ -130,17 +130,17 @@ export default class StackView extends React.Component<Props, State> {
openingRouteKeys = [...openingRouteKeys, nextFocusedRoute.key];
closingRouteKeys = closingRouteKeys.filter(
key => key !== nextFocusedRoute.key
(key) => key !== nextFocusedRoute.key
);
replacingRouteKeys = replacingRouteKeys.filter(
key => key !== nextFocusedRoute.key
(key) => key !== nextFocusedRoute.key
);
if (!routes.find(r => r.key === previousFocusedRoute.key)) {
if (!routes.find((r) => r.key === previousFocusedRoute.key)) {
// The previous focused route isn't present in state, we treat this as a replace
openingRouteKeys = openingRouteKeys.filter(
key => key !== previousFocusedRoute.key
(key) => key !== previousFocusedRoute.key
);
if (getAnimationTypeForReplace(nextFocusedRoute.key) === 'pop') {
@@ -153,7 +153,7 @@ export default class StackView extends React.Component<Props, State> {
// But since user configured it to animate the old screen like a pop, we need to add this without animation
// So remove it from `openingRouteKeys` which will remove the animation
openingRouteKeys = openingRouteKeys.filter(
key => key !== nextFocusedRoute.key
(key) => key !== nextFocusedRoute.key
);
// Keep the route being removed at the end to animate it out
@@ -165,7 +165,7 @@ export default class StackView extends React.Component<Props, State> {
];
closingRouteKeys = closingRouteKeys.filter(
key => key !== previousFocusedRoute.key
(key) => key !== previousFocusedRoute.key
);
// Keep the old route in the state because it's visible under the new route, and removing it will feel abrupt
@@ -176,7 +176,7 @@ export default class StackView extends React.Component<Props, State> {
}
}
}
} else if (!routes.find(r => r.key === previousFocusedRoute.key)) {
} else if (!routes.find((r) => r.key === previousFocusedRoute.key)) {
// The previously focused route was removed, we treat this as a pop
if (
@@ -188,10 +188,10 @@ export default class StackView extends React.Component<Props, State> {
// Sometimes a route can be closed before the opening animation finishes
// So we also need to remove it from the opening list
openingRouteKeys = openingRouteKeys.filter(
key => key !== previousFocusedRoute.key
(key) => key !== previousFocusedRoute.key
);
replacingRouteKeys = replacingRouteKeys.filter(
key => key !== previousFocusedRoute.key
(key) => key !== previousFocusedRoute.key
);
// Keep a copy of route being removed in the state to be able to animate it
@@ -273,13 +273,13 @@ export default class StackView extends React.Component<Props, State> {
private getPreviousRoute = ({ route }: { route: Route<string> }) => {
const { closingRouteKeys, replacingRouteKeys } = this.state;
const routes = this.state.routes.filter(
r =>
(r) =>
r.key === route.key ||
(!closingRouteKeys.includes(r.key) &&
!replacingRouteKeys.includes(r.key))
);
const index = routes.findIndex(r => r.key === route.key);
const index = routes.findIndex((r) => r.key === route.key);
return routes[index - 1];
};
@@ -323,12 +323,16 @@ export default class StackView extends React.Component<Props, State> {
private handleOpenRoute = ({ route }: { route: Route<string> }) => {
this.handleTransitionComplete({ route });
this.setState(state => ({
this.setState((state) => ({
routes: state.replacingRouteKeys.length
? state.routes.filter(r => !state.replacingRouteKeys.includes(r.key))
? state.routes.filter((r) => !state.replacingRouteKeys.includes(r.key))
: state.routes,
openingRouteKeys: state.openingRouteKeys.filter(key => key !== route.key),
closingRouteKeys: state.closingRouteKeys.filter(key => key !== route.key),
openingRouteKeys: state.openingRouteKeys.filter(
(key) => key !== route.key
),
closingRouteKeys: state.closingRouteKeys.filter(
(key) => key !== route.key
),
replacingRouteKeys: [],
}));
};
@@ -336,7 +340,7 @@ export default class StackView extends React.Component<Props, State> {
private handleCloseRoute = ({ route }: { route: Route<string> }) => {
const { state, navigation } = this.props;
if (state.routes.find(r => r.key === route.key)) {
if (state.routes.find((r) => r.key === route.key)) {
// If a route exists in state, trigger a pop
// This will happen in when the route was closed from the card component
// e.g. When the close animation triggered from a gesture ends
@@ -345,20 +349,20 @@ export default class StackView extends React.Component<Props, State> {
} else {
// While closing route we need to point to the previous one assuming that
// this previous one in routes array
const index = this.state.routes.findIndex(r => r.key === route.key);
const index = this.state.routes.findIndex((r) => r.key === route.key);
this.handleTransitionComplete({
route: this.state.routes[Math.max(index - 1, 0)],
});
// We need to clean up any state tracking the route and pop it immediately
this.setState(state => ({
routes: state.routes.filter(r => r.key !== route.key),
this.setState((state) => ({
routes: state.routes.filter((r) => r.key !== route.key),
openingRouteKeys: state.openingRouteKeys.filter(
key => key !== route.key
(key) => key !== route.key
),
closingRouteKeys: state.closingRouteKeys.filter(
key => key !== route.key
(key) => key !== route.key
),
}));
}
@@ -410,9 +414,9 @@ export default class StackView extends React.Component<Props, State> {
<GestureHandlerWrapper style={styles.container}>
<SafeAreaProviderCompat>
<SafeAreaConsumer>
{insets => (
{(insets) => (
<KeyboardManager enabled={keyboardHandlingEnabled !== false}>
{props => (
{(props) => (
<CardStack
mode={mode}
insets={insets as EdgeInsets}