Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/src/screens/BarButtonItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,9 @@ export default function BarButtonItemsExample() {
type: 'action',
icon: {
type: 'templateSource',
templateSource:
require('@assets/search_black.png'),
templateSource: require('@assets/search_black.png'),
},
onPress: () =>
Alert.alert('Sub Image Action pressed'),
onPress: () => Alert.alert('Sub Image Action pressed'),
},
],
},
Expand Down
15 changes: 11 additions & 4 deletions apps/src/screens/PreventRemove.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import React from 'react';
import { View, StyleSheet, TextInput, Platform, Alert, ScrollView, Text } from 'react-native';
import {
View,
StyleSheet,
TextInput,
Platform,
Alert,
ScrollView,
Text,
} from 'react-native';
import { usePreventRemove } from '@react-navigation/native';
import {
createNativeStackNavigator,
Expand Down Expand Up @@ -45,7 +53,7 @@ const PreventRemoveScreen = ({
'Discard changes?',
'You have unsaved changes. Discard them and leave the screen?',
[
{ text: "Don't leave", style: 'cancel', onPress: () => { } },
{ text: "Don't leave", style: 'cancel', onPress: () => {} },
{
text: 'Discard',
style: 'destructive',
Expand All @@ -59,8 +67,7 @@ const PreventRemoveScreen = ({
<View style={{ ...styles.container, backgroundColor: 'thistle' }}>
<ScrollView
contentContainerStyle={styles.contentContainer}
keyboardDismissMode="interactive"
>
keyboardDismissMode="interactive">
<TextInput
autoFocus
value={text}
Expand Down
4 changes: 1 addition & 3 deletions apps/src/screens/StackPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ const FullScreenModalScreen = ({
navigation,
}: FullScreenModalProps): React.JSX.Element => (
<View style={{ flex: 1 }}>
<ImageBackground
style={styles.image}
source={require('@assets/trees.jpg')}>
<ImageBackground style={styles.image} source={require('@assets/trees.jpg')}>
<Button
testID="stack-presentation-fullscreen-modal-go-back-button"
title="Go back"
Expand Down
44 changes: 23 additions & 21 deletions apps/src/screens/SwipeBackAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ interface ScreenBProps {
}

const ScreenB = ({ navigation }: ScreenBProps): React.JSX.Element => {
const [gestureType, setGestureType] = React.useState<NonNullable<NativeStackNavigationOptions['gestureType']>>('twoDimensionalSwipe');
const [gestureType, setGestureType] = React.useState<
NonNullable<NativeStackNavigationOptions['gestureType']>
>('twoDimensionalSwipe');

React.useEffect(() => {
navigation.setOptions({
Expand All @@ -39,25 +41,28 @@ const ScreenB = ({ navigation }: ScreenBProps): React.JSX.Element => {

return (
<View style={{ ...styles.container, backgroundColor: 'thistle' }}>
<SettingsPicker<NonNullable<NativeStackNavigationOptions['gestureType']>>
label="Stack animation"
value={gestureType}
onValueChange={setGestureType}
items={[
"swipeRight",
"swipeLeft",
"swipeUp",
"swipeDown",
"verticalSwipe",
"horizontalSwipe",
"twoDimensionalSwipe",
]}
/>
<Button title="Go ScreenC" onPress={() => navigation.navigate('ScreenC')} />
<SettingsPicker<NonNullable<NativeStackNavigationOptions['gestureType']>>
label="Stack animation"
value={gestureType}
onValueChange={setGestureType}
items={[
'swipeRight',
'swipeLeft',
'swipeUp',
'swipeDown',
'verticalSwipe',
'horizontalSwipe',
'twoDimensionalSwipe',
]}
/>
<Button
title="Go ScreenC"
onPress={() => navigation.navigate('ScreenC')}
/>
<Button title="Go back" onPress={() => navigation.goBack()} />
</View>
);
}
};

interface ScreenCProps {
navigation: NativeStackNavigationProp<StackParamList, 'ScreenC'>;
Expand All @@ -78,10 +83,7 @@ const App = (): React.JSX.Element => (
animation: 'none',
}}>
<Stack.Screen name="ScreenA" component={MainScreen} />
<Stack.Screen
name="ScreenB"
component={ScreenB}
/>
<Stack.Screen name="ScreenB" component={ScreenB} />
<Stack.Screen name="ScreenC" component={ScreenC} />
</Stack.Navigator>
);
Expand Down
14 changes: 9 additions & 5 deletions apps/src/shared/Rectangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import React from 'react';
import { ColorValue, View, ViewProps, ViewStyle } from 'react-native';

export interface RectangleProps extends ViewProps {
color?: ColorValue,
width?: ViewStyle['width'],
height?: ViewStyle['height'],
color?: ColorValue;
width?: ViewStyle['width'];
height?: ViewStyle['height'];
}

export function Rectangle(props: RectangleProps) {
const { color, width, height, style, ...remainingProps } = props;
return <View style={[{ backgroundColor: color, width, height }, style]} {...remainingProps} />;
return (
<View
style={[{ backgroundColor: color, width, height }, style]}
{...remainingProps}
/>
);
}

2 changes: 1 addition & 1 deletion apps/src/shared/Spacer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View } from 'react-native';

interface Props {
children?: ReactNode;
space?: number
space?: number;
}

export const Spacer = ({ children, space }: Props): React.JSX.Element => (
Expand Down
1 change: 0 additions & 1 deletion apps/src/shared/gamma/containers/shared/id-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export function generateID(): number {
GLOBAL_ID += 1;
return nextID;
}

7 changes: 6 additions & 1 deletion apps/src/shared/gamma/containers/stack/StackContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
return (
<Stack.Host ref={hostRef}>
{stackNavState.stack.map(
({ options: { headerConfig, ...options }, activityMode, routeKey, name }) => {
({
options: { headerConfig, ...options },
activityMode,
routeKey,
name,
}) => {
const stackNavigationContext: StackNavigationContextPayload = {
routeKey,
routeOptions: { ...options },
Expand Down
12 changes: 9 additions & 3 deletions apps/src/shared/gamma/containers/stack/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function navigationActionPushHandler(
const stack = state.stack;
const renderedRouteIndex = stack.findIndex(
route =>
route.name === action.routeName && route.activityMode === 'detached' && !route.isMarkedForDismissal,
route.name === action.routeName &&
route.activityMode === 'detached' &&
!route.isMarkedForDismissal,
);

if (renderedRouteIndex !== NOT_FOUND_INDEX) {
Expand Down Expand Up @@ -161,10 +163,14 @@ function navigationActionPopHandler(
}

// Pop operation on not-top screen is forbidden and might crash.
const topAttachedRouteIndex = state.stack.findLastIndex(r => r.activityMode === 'attached');
const topAttachedRouteIndex = state.stack.findLastIndex(
r => r.activityMode === 'attached',
);

if (topAttachedRouteIndex > routeIndex) {
console.warn(`[Stack] Can not perform pop action on route: ${action.routeKey} - not a top screen`);
console.warn(
`[Stack] Can not perform pop action on route: ${action.routeKey} - not a top screen`,
);
return state;
}

Expand Down
29 changes: 16 additions & 13 deletions apps/src/shared/gamma/containers/tabs/TabsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import { useComponentsByName } from '../shared/use-components-by-name';
export function TabsContainer(props: TabsContainerProps) {
RNSLog.info('TabsContainer render');

const {
routeConfigs,
defaultRouteName,
onTabSelected,
...restProps
} = props;
const { routeConfigs, defaultRouteName, onTabSelected, ...restProps } = props;

useSanitizeRouteConfigs(routeConfigs);

Expand Down Expand Up @@ -137,7 +132,9 @@ function useSanitizeRouteConfigs(routeConfigs: TabRouteConfig[]) {
}
}

function useTabsNavigationMethods(dispatch: React.Dispatch<TabsNavigationAction>): TabsNavigationMethods {
function useTabsNavigationMethods(
dispatch: React.Dispatch<TabsNavigationAction>,
): TabsNavigationMethods {
const setRouteOptions = React.useCallback(
(routeKey: string, options: Partial<TabRouteOptions>) => {
dispatch({ type: 'set-options', routeKey, options });
Expand All @@ -148,14 +145,20 @@ function useTabsNavigationMethods(dispatch: React.Dispatch<TabsNavigationAction>
const selectTab: SelectTabMethod = React.useCallback(
(routeKey: string, forceAction?: boolean) => {
const shouldForceAction = forceAction ?? false;
dispatch({ type: 'tab-select', routeKey, forceAction: shouldForceAction });
dispatch({
type: 'tab-select',
routeKey,
forceAction: shouldForceAction,
});
},
[dispatch],
);


return React.useMemo(() => ({
setRouteOptions,
selectTab
}), [setRouteOptions, selectTab]);
return React.useMemo(
() => ({
setRouteOptions,
selectTab,
}),
[setRouteOptions, selectTab],
);
}
5 changes: 2 additions & 3 deletions apps/src/shared/gamma/containers/tabs/TabsContainer.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export type TabsNavigationAction =

export type TabsHostConfig = Omit<
TabsHostProps,
| 'children'
| 'navStateRequest'
'children' | 'navStateRequest'
>;

export type TabsContainerProps = Omit<
Expand Down Expand Up @@ -108,4 +107,4 @@ export type SelectTabMethod = (routeKey: string, forceAction?: boolean) => void;
export type TabsNavigationMethods = {
setRouteOptions: SetTabOptionsMethod;
selectTab: SelectTabMethod;
}
};
27 changes: 16 additions & 11 deletions apps/src/shared/gamma/containers/tabs/TabsContainerItem.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import React from 'react';
import { Tabs } from "react-native-screens";
import { Tabs } from 'react-native-screens';
import type { TabRouteConfig } from './TabsContainer.types';
import type { TabsContainerItemProps } from './TabsContainerItem.types';
import { SafeAreaView, type SafeAreaViewProps } from 'react-native-screens/experimental';
import {
SafeAreaView,
type SafeAreaViewProps,
} from 'react-native-screens/experimental';
import { Platform } from 'react-native';
import { TabsNavigationContext } from './contexts/TabsNavigationContext';
import { RNSLog } from 'react-native-screens/private';

export const TabsContainerItem = React.memo(TabsContainerItemImpl);

function TabsContainerItemImpl(props: TabsContainerItemProps) {

RNSLog.info(
`TabsContainerItem render: ${props.route.routeKey} ${props.isSelected ? '(selected)' : ''
`TabsContainerItem render: ${props.route.routeKey} ${
props.isSelected ? '(selected)' : ''
} ${props.pendingForUpdate ? '(pending)' : ''}`,
);

Expand All @@ -24,18 +27,21 @@ function TabsContainerItemImpl(props: TabsContainerItemProps) {
selectTab: props.navMethods.selectTab,
isSelected: props.isSelected,
shouldRenderContents: props.isSelected || props.pendingForUpdate,
}
}, [props.route.routeKey, props.route.options, props.navMethods, props.isSelected, props.pendingForUpdate]);
};
}, [
props.route.routeKey,
props.route.options,
props.navMethods,
props.isSelected,
props.pendingForUpdate,
]);

const { safeAreaConfiguration, ...nativeOptions } = props.route.options ?? {};

const screenKey = props.route.routeKey;

return (
<Tabs.Screen
key={screenKey}
{...nativeOptions}
screenKey={screenKey}>
<Tabs.Screen key={screenKey} {...nativeOptions} screenKey={screenKey}>
<TabsNavigationContext value={tabsNavigationContext}>
{getContent(props.Component, safeAreaConfiguration)}
</TabsNavigationContext>
Expand Down Expand Up @@ -82,4 +88,3 @@ function getSafeAreaViewEdges(

return { ...defaultEdges, ...edges };
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
* updateHostConfig (via TabsHostConfigContext) rather than prop changes.
*/
export function TabsContainerWithHostConfigContext(props: TabsContainerProps) {
const {
routeConfigs,
defaultRouteName,
...hostProps
} = props;
const { routeConfigs, defaultRouteName, ...hostProps } = props;

const [hostConfig, setHostConfig] = React.useState<TabsHostConfig>(hostProps);

Expand All @@ -47,4 +43,3 @@ export function TabsContainerWithHostConfigContext(props: TabsContainerProps) {
</TabsHostConfigContext>
);
}

4 changes: 1 addition & 3 deletions apps/src/shared/gamma/containers/tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export type {
TabsContainerState,
} from './TabsContainer.types';

export type {
TabsContainerItemProps
} from './TabsContainerItem.types.ts'
export type { TabsContainerItemProps } from './TabsContainerItem.types.ts';

export type { TabsNavigationContextPayload } from './contexts/TabsNavigationContext';
export type { TabsHostConfigContextPayload } from './contexts/TabsHostConfigContext';
Expand Down
5 changes: 4 additions & 1 deletion apps/src/shared/gamma/containers/tabs/presets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { TabRouteOptions } from './TabsContainer.types';

export const DEFAULT_TAB_ROUTE_OPTIONS: Pick<TabRouteOptions, 'android' | 'ios'> = {
export const DEFAULT_TAB_ROUTE_OPTIONS: Pick<
TabRouteOptions,
'android' | 'ios'
> = {
android: {
icon: {
type: 'imageSource',
Expand Down
5 changes: 4 additions & 1 deletion apps/src/shared/gamma/containers/tabs/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function tabsActionSelectTabHandler(
return state;
}

if (state.confirmedState.selectedRouteKey === action.routeKey && !action.forceAction) {
if (
state.confirmedState.selectedRouteKey === action.routeKey &&
!action.forceAction
) {
return state;
}

Expand Down
1 change: 0 additions & 1 deletion apps/src/shared/utils/deep-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ function isMergeableObject(val: unknown): val is object {
!React.isValidElement(val)
);
}

Loading
Loading