Skip to content

Commit 00a9547

Browse files
authored
Merge pull request #60262 from margelo/@chrispader/fix-bottom-safe-area-regressions
[CP Staging] fix: Edge-to-edge bottom safe area padding fixes and `NewChatSelectorPage` refactoring
2 parents ee9ae8b + b7d5d2f commit 00a9547

File tree

6 files changed

+103
-141
lines changed

6 files changed

+103
-141
lines changed

src/components/DatePicker/CalendarPicker/YearPickerModal.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
5555
hideModalContentWhileAnimating
5656
useNativeDriver
5757
shouldHandleNavigationBack
58+
enableEdgeToEdgeBottomSafeAreaPadding
5859
>
5960
<ScreenWrapper
6061
style={[styles.pb0]}
6162
includePaddingTop={false}
62-
includeSafeAreaPaddingBottom
63+
enableEdgeToEdgeBottomSafeAreaPadding
6364
testID={YearPickerModal.displayName}
6465
>
6566
<HeaderWithBackButton
@@ -83,6 +84,7 @@ function YearPickerModal({isVisible, years, currentYear = new Date().getFullYear
8384
shouldStopPropagation
8485
shouldUseDynamicMaxToRenderPerBatch
8586
ListItem={RadioListItem}
87+
addBottomSafeAreaPadding
8688
/>
8789
</ScreenWrapper>
8890
</Modal>

src/components/ScreenWrapper.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type ScreenWrapperProps = {
7979
* Search 'switch(behavior)' in ./node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js for more context */
8080
keyboardAvoidingViewBehavior?: 'padding' | 'height' | 'position';
8181

82+
/** The vertical offset to pass to the KeyboardAvoidingView */
83+
keyboardVerticalOffset?: number;
84+
8285
/** Whether KeyboardAvoidingView should be enabled. Use false for screens where this functionality is not necessary */
8386
shouldEnableKeyboardAvoidingView?: boolean;
8487

@@ -152,6 +155,7 @@ function ScreenWrapper(
152155
shouldEnableMinHeight = false,
153156
includePaddingTop = true,
154157
keyboardAvoidingViewBehavior = 'padding',
158+
keyboardVerticalOffset,
155159
includeSafeAreaPaddingBottom: includeSafeAreaPaddingBottomProp = true,
156160
shouldEnableKeyboardAvoidingView = true,
157161
shouldEnablePickerAvoiding = true,
@@ -438,6 +442,7 @@ function ScreenWrapper(
438442
// Whether the mobile offline indicator or the content in general
439443
// should be offset by the bottom safe area padding when the keyboard is open.
440444
shouldOffsetBottomSafeAreaPadding={shouldKeyboardOffsetBottomSafeAreaPadding || shouldOffsetMobileOfflineIndicator}
445+
keyboardVerticalOffset={keyboardVerticalOffset}
441446
>
442447
<PickerAvoidingView
443448
style={isAvoidingViewportScroll ? [styles.h100, {marginTop: 1}] : styles.flex1}

src/hooks/useBottomSafeSafeAreaPaddingStyle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type UseBottomSafeAreaPaddingStyleParams = {
1717
style?: StyleProp<ViewStyle>;
1818

1919
/** The style property to use for applying the bottom safe area padding. */
20-
styleProperty?: 'paddingBottom' | 'bottom';
20+
styleProperty?: 'paddingBottom' | 'marginBottom' | 'bottom';
2121

2222
/** The additional padding to add to the bottom of the content. */
2323
additionalPaddingBottom?: number;

src/pages/NewChatPage.tsx

+24-46
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
44
import {Keyboard} from 'react-native';
55
import {useOnyx} from 'react-native-onyx';
66
import Button from '@components/Button';
7-
import ImportedStateIndicator from '@components/ImportedStateIndicator';
8-
import KeyboardAvoidingView from '@components/KeyboardAvoidingView';
9-
import OfflineIndicator from '@components/OfflineIndicator';
107
import {useOptionsList} from '@components/OptionListContextProvider';
118
import {PressableWithFeedback} from '@components/Pressable';
129
import ReferralProgramCTA from '@components/ReferralProgramCTA';
@@ -20,9 +17,7 @@ import useDebouncedState from '@hooks/useDebouncedState';
2017
import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners';
2118
import useLocalize from '@hooks/useLocalize';
2219
import useNetwork from '@hooks/useNetwork';
23-
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2420
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
25-
import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings';
2621
import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus';
2722
import useThemeStyles from '@hooks/useThemeStyles';
2823
import {navigateToAndOpenReport, searchInServer, setGroupDraft} from '@libs/actions/Report';
@@ -144,11 +139,9 @@ function NewChatPage() {
144139
const {isOffline} = useNetwork();
145140
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to show offline indicator on small screen only
146141
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
147-
const {isSmallScreenWidth} = useResponsiveLayout();
148142
const styles = useThemeStyles();
149143
const personalData = useCurrentUserPersonalDetails();
150144
const {top} = useSafeAreaInsets();
151-
const {insets, safeAreaPaddingBottomStyle} = useSafeAreaPaddings();
152145
const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false});
153146
const selectionListRef = useRef<SelectionListHandle>(null);
154147

@@ -339,50 +332,35 @@ function NewChatPage() {
339332

340333
return (
341334
<ScreenWrapper
342-
shouldEnableKeyboardAvoidingView={false}
343-
includeSafeAreaPaddingBottom
344-
shouldShowOfflineIndicator={false}
335+
enableEdgeToEdgeBottomSafeAreaPadding
345336
includePaddingTop={false}
346337
shouldEnablePickerAvoiding={false}
347-
testID={NewChatPage.displayName}
338+
keyboardVerticalOffset={variables.contentHeaderHeight + top + variables.tabSelectorButtonHeight + variables.tabSelectorButtonPadding}
348339
// Disable the focus trap of this page to activate the parent focus trap in `NewChatSelectorPage`.
349340
focusTrapSettings={{active: false}}
341+
testID={NewChatPage.displayName}
350342
>
351-
<KeyboardAvoidingView
352-
style={styles.flex1}
353-
behavior="padding"
354-
// Offset is needed as KeyboardAvoidingView in nested inside of TabNavigator instead of wrapping whole screen.
355-
// This is because when wrapping whole screen the screen was freezing when changing Tabs.
356-
keyboardVerticalOffset={variables.contentHeaderHeight + top + variables.tabSelectorButtonHeight + variables.tabSelectorButtonPadding}
357-
>
358-
<SelectionList<Option & ListItem>
359-
ref={selectionListRef}
360-
ListItem={UserListItem}
361-
sections={areOptionsInitialized ? sections : CONST.EMPTY_ARRAY}
362-
textInputValue={searchTerm}
363-
textInputHint={isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''}
364-
onChangeText={setSearchTerm}
365-
textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')}
366-
headerMessage={headerMessage}
367-
onSelectRow={selectOption}
368-
shouldSingleExecuteRowSelect
369-
onConfirm={(e, option) => (selectedOptions.length > 0 ? createGroup() : selectOption(option))}
370-
rightHandSideComponent={itemRightSideComponent}
371-
footerContent={footerContent}
372-
showLoadingPlaceholder={!areOptionsInitialized}
373-
shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()}
374-
isLoadingNewOptions={!!isSearchingForReports}
375-
initiallyFocusedOptionKey={firstKeyForList}
376-
shouldTextInputInterceptSwipe
377-
confirmButtonStyles={insets.bottom ? [safeAreaPaddingBottomStyle, styles.mb5] : undefined}
378-
/>
379-
{isSmallScreenWidth && (
380-
<>
381-
<OfflineIndicator />
382-
<ImportedStateIndicator />
383-
</>
384-
)}
385-
</KeyboardAvoidingView>
343+
<SelectionList<Option & ListItem>
344+
ref={selectionListRef}
345+
ListItem={UserListItem}
346+
sections={areOptionsInitialized ? sections : CONST.EMPTY_ARRAY}
347+
textInputValue={searchTerm}
348+
textInputHint={isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''}
349+
onChangeText={setSearchTerm}
350+
textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')}
351+
headerMessage={headerMessage}
352+
onSelectRow={selectOption}
353+
shouldSingleExecuteRowSelect
354+
onConfirm={(e, option) => (selectedOptions.length > 0 ? createGroup() : selectOption(option))}
355+
rightHandSideComponent={itemRightSideComponent}
356+
footerContent={footerContent}
357+
showLoadingPlaceholder={!areOptionsInitialized}
358+
shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()}
359+
isLoadingNewOptions={!!isSearchingForReports}
360+
initiallyFocusedOptionKey={firstKeyForList}
361+
shouldTextInputInterceptSwipe
362+
addBottomSafeAreaPadding
363+
/>
386364
</ScreenWrapper>
387365
);
388366
}

src/pages/NewChatSelectorPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function NewChatSelectorPage() {
4141

4242
return (
4343
<ScreenWrapper
44+
enableEdgeToEdgeBottomSafeAreaPadding
4445
shouldEnableKeyboardAvoidingView={false}
45-
includeSafeAreaPaddingBottom={false}
4646
shouldShowOfflineIndicator={false}
4747
shouldEnableMaxHeight
4848
testID={NewChatSelectorPage.displayName}

0 commit comments

Comments
 (0)