-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix(mobile): reserve the bottom safe area on Android surfaces #6003
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
Open
PollyGlot
wants to merge
2
commits into
pingdotgg:main
Choose a base branch
from
PollyGlot:fix/mobile-bottom-safe-area-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
oxlint-plugin-t3code/rules/require-bottom-safe-area-inset.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import { assert, describe } from "@effect/vitest"; | ||
|
|
||
| import { createOxlintRuleHarness } from "../test/utils.ts"; | ||
|
|
||
| const rule = createOxlintRuleHarness("t3code/require-bottom-safe-area-inset", { | ||
| filename: "fixture.tsx", | ||
| }); | ||
|
|
||
| describe("t3code/require-bottom-safe-area-inset", () => { | ||
| rule.valid( | ||
| "allows bottom offsets outside React Native files", | ||
| ` | ||
| export const style = { position: "absolute", bottom: 16, right: 16 }; | ||
| `, | ||
| ); | ||
|
|
||
| rule.valid( | ||
| "allows a floating button that reserves the safe-area inset", | ||
| ` | ||
| import { Pressable } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| export function ShowKeyboardButton() { | ||
| const insets = useSafeAreaInsets(); | ||
| return ( | ||
| <Pressable | ||
| style={{ position: "absolute", bottom: Math.max(insets.bottom, 16) + 16, right: 16 }} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.valid( | ||
| "allows an edge-attached overlay whose child owns the padding", | ||
| ` | ||
| import { View } from "react-native"; | ||
| import { KeyboardStickyView } from "react-native-keyboard-controller"; | ||
|
|
||
| export function ComposerOverlay(props: { readonly bottomInset: number }) { | ||
| return ( | ||
| <KeyboardStickyView style={{ position: "absolute", bottom: 0, left: 0, right: 0 }}> | ||
| <View style={{ paddingBottom: props.bottomInset }} /> | ||
| </KeyboardStickyView> | ||
| ); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.valid( | ||
| "allows list padding that is derived from the inset", | ||
| ` | ||
| import { FlatList } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| export function FileList() { | ||
| const insets = useSafeAreaInsets(); | ||
| return ( | ||
| <FlatList | ||
| data={[]} | ||
| renderItem={() => null} | ||
| contentContainerStyle={{ paddingTop: 8, paddingBottom: Math.max(insets.bottom, 18) + 18 }} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.valid( | ||
| "allows a nested callback that closes over its component's inset", | ||
| ` | ||
| import { FlatList, View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| export function FileList() { | ||
| const insets = useSafeAreaInsets(); | ||
| return ( | ||
| <FlatList | ||
| data={[]} | ||
| renderItem={() => <View style={{ position: "absolute", bottom: insets.bottom + 8 }} />} | ||
| contentContainerStyle={{ paddingBottom: insets.bottom }} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports a component that ignores the inset even when a sibling component reads it", | ||
| ` | ||
| import { Pressable, View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| function Header() { | ||
| const insets = useSafeAreaInsets(); | ||
| return <View style={{ paddingBottom: insets.bottom }} />; | ||
| } | ||
|
|
||
| export function Screen() { | ||
| return ( | ||
| <View> | ||
| <Header /> | ||
| <Pressable style={{ position: "absolute", bottom: 16, right: 16 }} /> | ||
| </View> | ||
| ); | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports a fixed bottom padding inside a style array", | ||
| ` | ||
| import { FlatList, StyleSheet } from "react-native"; | ||
|
|
||
| const styles = StyleSheet.create({ base: { paddingTop: 8 } }); | ||
|
|
||
| export function FileList() { | ||
| return ( | ||
| <FlatList | ||
| data={[]} | ||
| renderItem={() => null} | ||
| contentContainerStyle={[styles.base, { paddingBottom: 8 }]} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports a floating button pinned with a fixed bottom offset", | ||
| ` | ||
| import { Pressable } from "react-native"; | ||
|
|
||
| export function ShowKeyboardButton() { | ||
| return <Pressable style={{ position: "absolute", bottom: 16, right: 16 }} />; | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports list content padding that ignores the bottom inset", | ||
| ` | ||
| import { FlatList } from "react-native"; | ||
|
|
||
| export function FileList() { | ||
| return ( | ||
| <FlatList | ||
| data={[]} | ||
| renderItem={() => null} | ||
| contentContainerStyle={{ paddingTop: 8, paddingBottom: 8 }} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /insets\.bottom/); | ||
| }, | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.