From 0b2a3fd42421d8ffb35bab0fba628beb7011b68b Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 09:32:02 +0200 Subject: [PATCH 1/6] Update the code to use constant instead of raw numeric value --- guides/GUIDE_FOR_LIBRARY_AUTHORS.md | 4 ++-- native-stack/README.md | 2 +- src/components/Screen.tsx | 9 ++++++--- src/index.tsx | 17 +++++++++++------ src/native-stack/types.tsx | 2 +- src/types.tsx | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/guides/GUIDE_FOR_LIBRARY_AUTHORS.md b/guides/GUIDE_FOR_LIBRARY_AUTHORS.md index 4689105491..5c8522a1fb 100644 --- a/guides/GUIDE_FOR_LIBRARY_AUTHORS.md +++ b/guides/GUIDE_FOR_LIBRARY_AUTHORS.md @@ -191,7 +191,7 @@ Boolean indicating whether the sheet shows a grabber at the top. Works only when `stackPresentation` is set to `formSheet`. Defaults to `false`. -### `sheetLargestUndimmedDetent` (iOS only) +### `sheetLargestUndimmedDetent` The largest sheet detent for which a view underneath won't be dimmed. Works only when `presentation` is set to `formSheet`. @@ -202,7 +202,7 @@ there won't be a dimming view beneath the sheet. There also legacy & **deprecated** prop values available, which work in tandem with corresponding legacy proop values for `sheetAllowedDetents` prop. -Defaults to `-1`, indicating that the dimming view should be always present. +Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. ### `stackAnimation` diff --git a/native-stack/README.md b/native-stack/README.md index 9c8f6429d0..3bdade4d48 100644 --- a/native-stack/README.md +++ b/native-stack/README.md @@ -307,7 +307,7 @@ there won't be a dimming view beneath the sheet. There also legacy & **deprecated** prop values available, which work in tandem with corresponding legacy prop values for `sheetAllowedDetents` prop. -Defaults to `-1`, indicating that the dimming view should be always present. +Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. #### `stackAnimation` diff --git a/src/components/Screen.tsx b/src/components/Screen.tsx index aa1c1440d0..2ec94e5ffe 100644 --- a/src/components/Screen.tsx +++ b/src/components/Screen.tsx @@ -49,6 +49,9 @@ const SHEET_COMPAT_LARGE = [1.0]; const SHEET_COMPAT_MEDIUM = [0.5]; const SHEET_COMPAT_ALL = [0.5, 1.0]; +export const SHEET_DIMMED_ALWAYS = -1; +// const SHEET_DIMMED_NEVER = 9999; + // These exist to transform old 'legacy' values used by the formsheet API to the new API shape. // We can get rid of it, once we get rid of support for legacy values: 'large', 'medium', 'all'. function resolveSheetAllowedDetents( @@ -80,10 +83,10 @@ function resolveSheetLargestUndimmedDetent( } else if (lud === 'medium') { return 0; } else if (lud === 'all') { - return -1; + return SHEET_DIMMED_ALWAYS; } else { // Safe default, every detent is dimmed - return -1; + return SHEET_DIMMED_ALWAYS; } } @@ -112,7 +115,7 @@ export const InnerScreen = React.forwardRef( const { // formSheet presentation related props sheetAllowedDetents = [1.0], - sheetLargestUndimmedDetent = -1, + sheetLargestUndimmedDetent = SHEET_DIMMED_ALWAYS, sheetGrabberVisible = false, sheetCornerRadius = -1.0, sheetExpandsWhenScrolledToEdge = true, diff --git a/src/index.tsx b/src/index.tsx index 0e2a7dc5bb..6aaef6bf2c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ export * from './types'; -/* +/** * Core */ export { @@ -11,7 +11,7 @@ export { shouldUseActivityState, } from './core'; -/* +/** * RNS Components */ export { @@ -57,17 +57,17 @@ export { NativeScreenContentWrapper, } from './components/ScreenContentWrapper'; -/* +/** * Modules */ export { default as NativeScreensModule } from './fabric/NativeScreensModule'; -/* +/** * Contexts */ export { GHContext } from './native-stack/contexts/GHContext'; -/* +/** * Utils */ export { @@ -76,7 +76,12 @@ export { executeNativeBackPress, } from './utils'; -/* +/** + * Constants + */ +export { SHEET_DIMMED_ALWAYS } from './components/Screen'; + +/** * Hooks */ export { default as useTransitionProgress } from './useTransitionProgress'; diff --git a/src/native-stack/types.tsx b/src/native-stack/types.tsx index 12ff6f82a3..6cf9e60443 100644 --- a/src/native-stack/types.tsx +++ b/src/native-stack/types.tsx @@ -426,7 +426,7 @@ export type NativeStackNavigationOptions = { * This prop can be set to an number, which indicates index of detent in `sheetAllowedDetents` array for which * there won't be a dimming view beneath the sheet. * - * Defaults to `-1`, indicating that the dimming view should be always present. + * Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. */ sheetLargestUndimmedDetent?: ScreenProps['sheetLargestUndimmedDetent']; /** diff --git a/src/types.tsx b/src/types.tsx index ceb580ccb7..9ebb175bf1 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -354,7 +354,7 @@ export interface ScreenProps extends ViewProps { * There also legacy & **deprecated** prop values available, which work in tandem with * corresponding legacy prop values for `sheetAllowedDetents` prop. * - * Defaults to `-1`, indicating that the dimming view should be always present. + * Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. */ sheetLargestUndimmedDetent?: number | 'medium' | 'large' | 'all'; /** From d54899eace368208a89eaa29b777a22b44de5d65 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 09:32:18 +0200 Subject: [PATCH 2/6] TOREVERT: update react navigation --- react-navigation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-navigation b/react-navigation index c7cbe96430..324161c65b 160000 --- a/react-navigation +++ b/react-navigation @@ -1 +1 @@ -Subproject commit c7cbe9643091a9a91dbed6b18fd579166d34107a +Subproject commit 324161c65bab856beec51d54d290d950dd146026 From 35bd17ea336690dac174a2121ef164495143da6f Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 09:52:03 +0200 Subject: [PATCH 3/6] Use new constant in example --- apps/src/tests/Test1649/state.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/src/tests/Test1649/state.tsx b/apps/src/tests/Test1649/state.tsx index fe5aec1169..21dcafd167 100644 --- a/apps/src/tests/Test1649/state.tsx +++ b/apps/src/tests/Test1649/state.tsx @@ -1,12 +1,13 @@ import * as React from 'react'; import * as jotai from 'jotai'; import { AllowedDetentsType, SheetOptions } from './types'; +import { SHEET_DIMMED_ALWAYS } from 'react-native-screens'; export const sheetInitialOptions: SheetOptions = { sheetAllowedDetents: [0.4, 0.6, 0.9], // sheetAllowedDetents: [0.6], // sheetAllowedDetents: 'fitToContents', - sheetLargestUndimmedDetent: 2, + sheetLargestUndimmedDetent: SHEET_DIMMED_ALWAYS, sheetGrabberVisible: false, sheetCornerRadius: 24, sheetExpandsWhenScrolledToEdge: true, From faf088247cb6bef027d6a75b21efcddaaf96ac7e Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 10:56:50 +0200 Subject: [PATCH 4/6] Migrate towards string options --- guides/GUIDE_FOR_LIBRARY_AUTHORS.md | 13 +++++++++---- native-stack/README.md | 9 +++++++-- src/components/Screen.tsx | 14 ++++++++++---- src/index.tsx | 5 ----- src/native-stack/types.tsx | 10 +++++++++- src/native-stack/views/NativeStackView.tsx | 2 +- src/types.tsx | 17 ++++++++++++++--- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/guides/GUIDE_FOR_LIBRARY_AUTHORS.md b/guides/GUIDE_FOR_LIBRARY_AUTHORS.md index 5c8522a1fb..2ed6bcf9ef 100644 --- a/guides/GUIDE_FOR_LIBRARY_AUTHORS.md +++ b/guides/GUIDE_FOR_LIBRARY_AUTHORS.md @@ -194,15 +194,20 @@ Defaults to `false`. ### `sheetLargestUndimmedDetent` The largest sheet detent for which a view underneath won't be dimmed. -Works only when `presentation` is set to `formSheet`. +Works only when `stackPresentation` is set to `formSheet`. This prop can be set to an number, which indicates index of detent in `sheetAllowedDetents` array for which there won't be a dimming view beneath the sheet. -There also legacy & **deprecated** prop values available, which work in tandem with -corresponding legacy proop values for `sheetAllowedDetents` prop. +Additionaly there are following options available: + +* `none` - there will be dimming view for all detents levels, +* `largest` - there won't be a dimming view for any detent level. + +There also legacy & **deprecated** prop values available: `medium`, `large` (don't confuse with `largest`), `all`, which work in tandem with +corresponding legacy prop values for `sheetAllowedDetents` prop. -Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. +Defaults to `none`, indicating that the dimming view should be always present. ### `stackAnimation` diff --git a/native-stack/README.md b/native-stack/README.md index 3bdade4d48..c6649591e6 100644 --- a/native-stack/README.md +++ b/native-stack/README.md @@ -304,10 +304,15 @@ Works only when `stackPresentation` is set to `formSheet`. This prop can be set to an number, which indicates index of detent in `sheetAllowedDetents` array for which there won't be a dimming view beneath the sheet. -There also legacy & **deprecated** prop values available, which work in tandem with +Additionaly there are following options available: + +* `none` - there will be dimming view for all detents levels, +* `largest` - there won't be a dimming view for any detent level. + +There also legacy & **deprecated** prop values available: `medium`, `large` (don't confuse with `largest`), `all`, which work in tandem with corresponding legacy prop values for `sheetAllowedDetents` prop. -Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. +Defaults to `none`, indicating that the dimming view should be always present. #### `stackAnimation` diff --git a/src/components/Screen.tsx b/src/components/Screen.tsx index 2ec94e5ffe..ab2bfaf1a6 100644 --- a/src/components/Screen.tsx +++ b/src/components/Screen.tsx @@ -49,7 +49,7 @@ const SHEET_COMPAT_LARGE = [1.0]; const SHEET_COMPAT_MEDIUM = [0.5]; const SHEET_COMPAT_ALL = [0.5, 1.0]; -export const SHEET_DIMMED_ALWAYS = -1; +const SHEET_DIMMED_ALWAYS = -1; // const SHEET_DIMMED_NEVER = 9999; // These exist to transform old 'legacy' values used by the formsheet API to the new API shape. @@ -75,15 +75,18 @@ function resolveSheetAllowedDetents( function resolveSheetLargestUndimmedDetent( lud: ScreenProps['sheetLargestUndimmedDetent'], + largestDetentIndex: number, ): number { if (typeof lud === 'number') { return lud; + } else if (lud === 'largest') { + return largestDetentIndex; + } else if (lud === 'none' || lud === 'all') { + return SHEET_DIMMED_ALWAYS; } else if (lud === 'large') { return 1; } else if (lud === 'medium') { return 0; - } else if (lud === 'all') { - return SHEET_DIMMED_ALWAYS; } else { // Safe default, every detent is dimmed return SHEET_DIMMED_ALWAYS; @@ -130,7 +133,10 @@ export const InnerScreen = React.forwardRef( const resolvedSheetAllowedDetents = resolveSheetAllowedDetents(sheetAllowedDetents); const resolvedSheetLargestUndimmedDetent = - resolveSheetLargestUndimmedDetent(sheetLargestUndimmedDetent); + resolveSheetLargestUndimmedDetent( + sheetLargestUndimmedDetent, + resolvedSheetAllowedDetents.length - 1, + ); // Due to how Yoga resolves layout, we need to have different components for modal nad non-modal screens const AnimatedScreen = Platform.OS === 'android' || diff --git a/src/index.tsx b/src/index.tsx index 6aaef6bf2c..b344112232 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -76,11 +76,6 @@ export { executeNativeBackPress, } from './utils'; -/** - * Constants - */ -export { SHEET_DIMMED_ALWAYS } from './components/Screen'; - /** * Hooks */ diff --git a/src/native-stack/types.tsx b/src/native-stack/types.tsx index 6cf9e60443..4c3f342625 100644 --- a/src/native-stack/types.tsx +++ b/src/native-stack/types.tsx @@ -426,7 +426,15 @@ export type NativeStackNavigationOptions = { * This prop can be set to an number, which indicates index of detent in `sheetAllowedDetents` array for which * there won't be a dimming view beneath the sheet. * - * Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. + * Additionaly there are following options available: + * + * * `none` - there will be dimming view for all detents levels, + * * `largest` - there won't be a dimming view for any detent level. + * + * There also legacy & **deprecated** prop values available: `medium`, `large` (don't confuse with `largest`), `all`, which work in tandem with + * corresponding legacy prop values for `sheetAllowedDetents` prop. + * + * Defaults to `none`, indicating that the dimming view should be always present. */ sheetLargestUndimmedDetent?: ScreenProps['sheetLargestUndimmedDetent']; /** diff --git a/src/native-stack/views/NativeStackView.tsx b/src/native-stack/views/NativeStackView.tsx index dec52bb618..9f00561282 100644 --- a/src/native-stack/views/NativeStackView.tsx +++ b/src/native-stack/views/NativeStackView.tsx @@ -195,7 +195,7 @@ const RouteView = ({ headerShown, hideKeyboardOnSwipe, homeIndicatorHidden, - sheetLargestUndimmedDetent = -1, + sheetLargestUndimmedDetent = 'none', sheetGrabberVisible = false, sheetCornerRadius = -1.0, sheetElevation = 24, diff --git a/src/types.tsx b/src/types.tsx index 9ebb175bf1..5c11e9556b 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -351,12 +351,23 @@ export interface ScreenProps extends ViewProps { * This prop can be set to an number, which indicates index of detent in `sheetAllowedDetents` array for which * there won't be a dimming view beneath the sheet. * - * There also legacy & **deprecated** prop values available, which work in tandem with + * Additionaly there are following options available: + * + * * `none` - there will be dimming view for all detents levels, + * * `largest` - there won't be a dimming view for any detent level. + * + * There also legacy & **deprecated** prop values available: `medium`, `large` (don't confuse with `largest`), `all`, which work in tandem with * corresponding legacy prop values for `sheetAllowedDetents` prop. * - * Defaults to `SHEET_DIMMED_ALWAYS`, indicating that the dimming view should be always present. + * Defaults to `none`, indicating that the dimming view should be always present. */ - sheetLargestUndimmedDetent?: number | 'medium' | 'large' | 'all'; + sheetLargestUndimmedDetent?: + | number + | 'none' + | 'largest' + | 'medium' + | 'large' + | 'all'; /** * Index of the detent the sheet should expand to after being opened. * Works only when `stackPresentation` is set to `formSheet`. From 296020321f70262f4fd8820b3a604e5ad708e7e4 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 10:57:03 +0200 Subject: [PATCH 5/6] TOREVERT: update react navigation --- react-navigation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-navigation b/react-navigation index 324161c65b..782248d992 160000 --- a/react-navigation +++ b/react-navigation @@ -1 +1 @@ -Subproject commit 324161c65bab856beec51d54d290d950dd146026 +Subproject commit 782248d9922c9e71ba65ea1d93b09abd6f84fe5c From e164aa174662511ab80a6d3cbdc17038e57e131e Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Mon, 30 Sep 2024 10:57:26 +0200 Subject: [PATCH 6/6] Update example to use new `none` options --- apps/src/tests/Test1649/state.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/src/tests/Test1649/state.tsx b/apps/src/tests/Test1649/state.tsx index 21dcafd167..5e9af4294d 100644 --- a/apps/src/tests/Test1649/state.tsx +++ b/apps/src/tests/Test1649/state.tsx @@ -1,13 +1,12 @@ import * as React from 'react'; import * as jotai from 'jotai'; import { AllowedDetentsType, SheetOptions } from './types'; -import { SHEET_DIMMED_ALWAYS } from 'react-native-screens'; export const sheetInitialOptions: SheetOptions = { sheetAllowedDetents: [0.4, 0.6, 0.9], // sheetAllowedDetents: [0.6], // sheetAllowedDetents: 'fitToContents', - sheetLargestUndimmedDetent: SHEET_DIMMED_ALWAYS, + sheetLargestUndimmedDetent: 'none', sheetGrabberVisible: false, sheetCornerRadius: 24, sheetExpandsWhenScrolledToEdge: true,