Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new way to handle insets in the app #53250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d1c57ec
feat: new way to handle insets in the app
kirillzyusko Nov 28, 2024
8e76218
Update src/hooks/useEdgeSpacing/index.ts
hannojg Nov 28, 2024
73cee7a
add const import
hannojg Nov 28, 2024
f08991f
fix safeAreaPaddingBottomStyle
hannojg Nov 28, 2024
69c8e29
fix a few screens
hannojg Nov 28, 2024
5832b1b
fix workspace invite page
hannojg Nov 28, 2024
c7ffc53
wip
hannojg Nov 29, 2024
9901700
fix: search filter search page
kirillzyusko Nov 29, 2024
0dfa4c2
fix profile page spacing
hannojg Nov 29, 2024
1f76a0e
fix workspace more features page
hannojg Nov 29, 2024
0c28b6c
wip: migrate FormWrapper
hannojg Nov 29, 2024
4bb5c4e
wip: migrate FormWrapper
hannojg Nov 29, 2024
3474886
wip
hannojg Nov 29, 2024
14ba19c
clean
hannojg Nov 29, 2024
e5f03b4
clean
hannojg Nov 29, 2024
8afb320
remove usage of useSafePaddingBottomStyle
hannojg Nov 29, 2024
bc37113
update docs
hannojg Nov 29, 2024
24e5f33
remove unused import
hannojg Nov 29, 2024
781ea28
fix: synchronous keyboard padding removal
kirillzyusko Nov 29, 2024
a2e5062
Merge branch 'feat/screen-wrapper-better-inset-padding-handling' of g…
hannojg Nov 29, 2024
a093da3
cleanup fixed footer
hannojg Nov 29, 2024
b793c60
remove useEdgeSpacing
hannojg Nov 29, 2024
3a1f021
Screens using FormProvider should use `includeSafeAreaPaddingBottom` …
hannojg Nov 29, 2024
4c4a2d7
add deprecation notice
hannojg Nov 29, 2024
1a69b72
fix code verification page
hannojg Nov 29, 2024
fdfdceb
fix more screens
hannojg Nov 29, 2024
56fec79
fix address page
hannojg Nov 29, 2024
1a0b9a1
fix: profile page
kirillzyusko Nov 29, 2024
a7c64ba
fix: some workspace screens keyboard padding
kirillzyusko Nov 29, 2024
286b679
fix: more workspace screens keyboard padding
kirillzyusko Nov 29, 2024
6bb138b
fix: even more workspace screens keyboard padding
kirillzyusko Nov 29, 2024
0edef30
add doc
hannojg Nov 29, 2024
f67832f
fix: even more changes
kirillzyusko Nov 29, 2024
321e524
update docs
hannojg Nov 29, 2024
5ca2ed7
fix RequestParticipantSelector
hannojg Nov 29, 2024
524966e
fix two more cases
hannojg Nov 29, 2024
222738c
fix: last screens migrated
kirillzyusko Nov 29, 2024
4333d2b
fix: search advanced filters page
kirillzyusko Nov 29, 2024
b59393f
fix: filter screens
kirillzyusko Nov 29, 2024
25127ff
fix: eslint partially
kirillzyusko Nov 29, 2024
1391c6c
fix: avoid double spacing in worksplace invite
kirillzyusko Nov 29, 2024
665fa49
fix: TextSelectorModal should always consume original insets
kirillzyusko Nov 29, 2024
ac6c8ea
remove useSafePaddingBottomStyle entirely
hannojg Nov 29, 2024
4d3d533
suppress eslint warnings
hannojg Nov 29, 2024
c4a8ca6
change deprecation notice
hannojg Nov 29, 2024
c9b8162
fix: 53207
kirillzyusko Nov 29, 2024
fc2cfdd
fix: onboarding keyboard -> button padding
kirillzyusko Nov 29, 2024
b0a2c51
fix: verification modal missing top padding
kirillzyusko Nov 29, 2024
69ee93e
fix: 53192
kirillzyusko Nov 29, 2024
064b321
fix: year modal wrong padding
kirillzyusko Nov 29, 2024
e5d7da8
fix: wrong bottom padding on workspace selection screen
kirillzyusko Nov 29, 2024
3061183
fix: category selector modal
kirillzyusko Nov 29, 2024
e365e1e
Merge branch 'main' into feat/screen-wrapper-better-inset-padding-han…
kirillzyusko Nov 30, 2024
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
9 changes: 6 additions & 3 deletions contributingGuides/FORMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ An example of this can be seen in the [ACHContractStep](https://github.com/Expen

### Safe Area Padding

Any `FormProvider.js` that has a button will also add safe area padding by default. If the `<FormProvider>` is inside a `<ScreenWrapper>`, we will want to disable the default safe area padding applied there e.g.
Any `FormProvider.tsx` that has a button at the bottom. If the `<FormProvider>` is inside a `<ScreenWrapper>`, the bottom safe area inset is handled automatically (`includeSafeAreaPaddingBottom` needs to be set to `true`, but its the default).
If you have custom requirements and can't use `<ScreenWrapper includeSafeAreaPaddingBottom={true}>`, you can use the `useStyledSafeAreaInsets()` hook:

```jsx
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
const { paddingTop, paddingBottom, safeAreaPaddingBottomStyle } = useStyledSafeAreaInsets();

<View styles={[safeAreaPaddingBottomStyle, styles.pb5]}>
<FormProvider>
{...}
</FormProvider>
</ScreenWrapper>
</View>
```

### Handling nested Pickers in Form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function CategorySelectorModal({policyID, isVisible, currentCategory, onCategory
<ScreenWrapper
style={[styles.pb0]}
includePaddingTop={false}
includeSafeAreaPaddingBottom={false}
includeSafeAreaPaddingBottom
shouldEnableKeyboardAvoidingView={false}
testID={CategorySelectorModal.displayName}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
<ScreenWrapper
style={[styles.pb0]}
includePaddingTop={false}
includeSafeAreaPaddingBottom={false}
includeSafeAreaPaddingBottom
testID={YearPickerModal.displayName}
>
<HeaderWithBackButton
Expand Down
6 changes: 1 addition & 5 deletions src/components/FixedFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {ReactNode} from 'react';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useThemeStyles from '@hooks/useThemeStyles';

type FixedFooterProps = {
Expand All @@ -14,16 +13,13 @@ type FixedFooterProps = {
};

function FixedFooter({style, children}: FixedFooterProps) {
const insets = useSafeAreaInsets();
const styles = useThemeStyles();

if (!children) {
return null;
}

const shouldAddBottomPadding = !insets.bottom;

return <View style={[styles.ph5, shouldAddBottomPadding && styles.pb5, styles.flexShrink0, style]}>{children}</View>;
return <View style={[styles.ph5, styles.pb5, styles.flexShrink0, style]}>{children}</View>;
}

FixedFooter.displayName = 'FixedFooter';
Expand Down
56 changes: 26 additions & 30 deletions src/components/Form/FormWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {Keyboard} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import FormElement from '@components/FormElement';
import SafeAreaConsumer from '@components/SafeAreaConsumer';
import type {SafeAreaChildrenProps} from '@components/SafeAreaConsumer/types';
import ScrollView from '@components/ScrollView';
import ScrollViewWithContext from '@components/ScrollViewWithContext';
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import type {OnyxFormKey} from '@src/ONYXKEYS';
Expand Down Expand Up @@ -60,6 +59,7 @@ function FormWrapper({
isSubmitDisabled = false,
}: FormWrapperProps) {
const styles = useThemeStyles();
const {paddingBottom: safeAreaInsetPaddingBottom} = useStyledSafeAreaInsets();
const formRef = useRef<RNScrollView>(null);
const formContentRef = useRef<View>(null);

Expand Down Expand Up @@ -99,11 +99,12 @@ function FormWrapper({
}, [errors, formState?.errorFields, inputRefs]);

const scrollViewContent = useCallback(
(safeAreaPaddingBottomStyle: SafeAreaChildrenProps['safeAreaPaddingBottomStyle']) => (
() => (
<FormElement
key={formID}
ref={formContentRef}
style={[style, safeAreaPaddingBottomStyle.paddingBottom ? safeAreaPaddingBottomStyle : styles.pb5]}
// Note: the paddingBottom is only grater 0 if no parent has applied the inset yet:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Note: the paddingBottom is only grater 0 if no parent has applied the inset yet:
// Note: the paddingBottom is only greater than 0 if no parent has applied the inset yet:

style={[style, {paddingBottom: safeAreaInsetPaddingBottom + styles.pb5.paddingBottom}]}
>
{children}
{isSubmitButtonVisible && (
Expand All @@ -128,7 +129,8 @@ function FormWrapper({
[
formID,
style,
styles.pb5,
safeAreaInsetPaddingBottom,
styles.pb5.paddingBottom,
styles.mh0,
styles.mt5,
styles.flex1,
Expand All @@ -153,33 +155,27 @@ function FormWrapper({
);

if (!shouldUseScrollView) {
return scrollViewContent({});
return scrollViewContent();
}

return (
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) =>
scrollContextEnabled ? (
<ScrollViewWithContext
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
{scrollViewContent(safeAreaPaddingBottomStyle)}
</ScrollViewWithContext>
) : (
<ScrollView
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
{scrollViewContent(safeAreaPaddingBottomStyle)}
</ScrollView>
)
}
</SafeAreaConsumer>
return scrollContextEnabled ? (
<ScrollViewWithContext
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
{scrollViewContent()}
</ScrollViewWithContext>
) : (
<ScrollView
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
{scrollViewContent()}
</ScrollView>
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {Ref} from 'react';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useSafePaddingBottomStyle from '@hooks/useSafePaddingBottomStyle';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlatform from '@libs/getPlatform';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -87,7 +86,6 @@ function FormAlertWithSubmitButton({
}: FormAlertWithSubmitButtonProps) {
const styles = useThemeStyles();
const style = [!footerContent ? {} : styles.mb3, buttonStyles];
const safePaddingBottomStyle = useSafePaddingBottomStyle();

// Disable pressOnEnter for Android Native to avoid issues with the Samsung keyboard,
// where pressing Enter saves the form instead of adding a new line in multiline input.
Expand All @@ -97,7 +95,7 @@ function FormAlertWithSubmitButton({

return (
<FormAlertWrapper
containerStyles={[styles.justifyContentEnd, safePaddingBottomStyle, containerStyles]}
containerStyles={[styles.justifyContentEnd, containerStyles]}
isAlertVisible={isAlertVisible}
isMessageHtml={isMessageHtml}
message={message}
Expand Down
2 changes: 1 addition & 1 deletion src/components/InteractiveStepWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function InteractiveStepWrapper(
<ScreenWrapper
ref={ref}
testID={wrapperID}
includeSafeAreaPaddingBottom={false}
includeSafeAreaPaddingBottom
shouldEnablePickerAvoiding={shouldEnablePickerAvoiding}
shouldEnableMaxHeight={shouldEnableMaxHeight}
shouldShowOfflineIndicator={shouldShowOfflineIndicator}
Expand Down
1 change: 1 addition & 0 deletions src/components/SafeAreaConsumer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type SafeAreaConsumerProps from './types';
/**
* This component is a light wrapper around the SafeAreaInsetsContext.Consumer. There are several places where we
* may need not just the insets, but the computed styles so we save a few lines of code with this.
* Note: if you're working within a <ScreenWrapper> please use `useStyledSafeAreaInsets` instead.
*/
function SafeAreaConsumer({children}: SafeAreaConsumerProps) {
const StyleUtils = useStyleUtils();
Expand Down
Loading
Loading