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

Fix: Add more space to bottom docked button #44761

Merged
merged 17 commits into from
Jul 25, 2024
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
4 changes: 3 additions & 1 deletion src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 Button from './Button';
import FormAlertWrapper from './FormAlertWrapper';
Expand Down Expand Up @@ -79,10 +80,11 @@ function FormAlertWithSubmitButton({
}: FormAlertWithSubmitButtonProps) {
const styles = useThemeStyles();
const style = [!footerContent ? {} : styles.mb3, buttonStyles];
const safePaddingBottomStyle = useSafePaddingBottomStyle();

return (
<FormAlertWrapper
containerStyles={[styles.justifyContentEnd, containerStyles]}
containerStyles={[styles.justifyContentEnd, safePaddingBottomStyle, containerStyles]}
isAlertVisible={isAlertVisible}
isMessageHtml={isMessageHtml}
message={message}
Expand Down
37 changes: 37 additions & 0 deletions src/hooks/useSafePaddingBottomStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {useEffect, useMemo, useState} from 'react';
import {Keyboard} from 'react-native';
import useStyledSafeAreaInsets from './useStyledSafeAreaInsets';
import useThemeStyles from './useThemeStyles';

// This hook is useful for adding extra bottom padding to a component based on the device's safe area
// If the device's safe area padding bottom is 0, the hook returns 0. Otherwise, it provides a padding bottom of 20.
// Use this to ensure content visibility and layout consistency across different devices.
const useSafePaddingBottomStyle = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some general documentation above about what this hook is for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for being a stickler, but I'm finding this comment a bit hard to follow. In the future, when should someone use this hook? Maybe if you can just explain that to me in words in a comment here, I can help you craft a code comment that is a bit more clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with you @puneetlath , @truph01 can you please follow up with this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@puneetlath

In the future, when should someone use this hook

This hook, useSafePaddingBottomStyle, is useful for adding extra bottom padding to a component based on the device's safe area. If the device's safe area padding bottom is 0, the hook returns 0. Otherwise, it provides a padding bottom of 20. Use this to ensure content visibility and layout consistency across different devices.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's beautiful. Very clear! Let's make that the comment.

const styles = useThemeStyles();
const [willKeyboardShow, setWillKeyboardShow] = useState<boolean>(false);
useEffect(() => {
const keyboardWillShowListener = Keyboard.addListener('keyboardWillShow', () => {
setWillKeyboardShow(true);
});
const keyboardWillHideListener = Keyboard.addListener('keyboardWillHide', () => {
setWillKeyboardShow(false);
});
return () => {
keyboardWillShowListener.remove();
keyboardWillHideListener.remove();
};
}, []);

const {paddingBottom} = useStyledSafeAreaInsets();

const extraPaddingBottomStyle = useMemo(() => {
// Do not add extra padding at the bottom if the keyboard is open or if there is no safe area bottom padding style.
if (willKeyboardShow || !paddingBottom) {
return {};
}
return styles.pb5;
}, [willKeyboardShow, paddingBottom, styles.pb5]);
return extraPaddingBottomStyle;
};

export default useSafePaddingBottomStyle;
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function IOURequestStepDate({
shouldShowNotFoundPage={shouldShowNotFound}
shouldShowWrapper
testID={IOURequestStepDate.displayName}
includeSafeAreaPaddingBottom={false}
>
<FormProvider
style={[styles.flexGrow1, styles.ph5]}
Expand Down
Loading