-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
6
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
abe23c8
fix(mobile): reserve the bottom safe area on Android surfaces
PollyGlot 1915291
fix(mobile): keep iOS bottom spacing unchanged, tighten the lint rule
PollyGlot b00ea3d
fix(mobile): reserve the file tree bottom inset on pre-glass iOS
PollyGlot cb88227
fix(lint): do not flag inline scroll views bounded by an explicit height
PollyGlot 7631785
fix(lint): merge style arrays and ignore percentage heights in the sa…
PollyGlot 7cc3cd5
fix(lint): judge wrapped style objects on their own inside arrays
PollyGlot 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
264 changes: 264 additions & 0 deletions
264
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,264 @@ | ||
| 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.valid( | ||
| "allows an inline scroll view bounded by an explicit height", | ||
| ` | ||
| import { ScrollView, Text } from "react-native"; | ||
|
|
||
| export function Caption(props: { readonly source: string }) { | ||
| return ( | ||
| <ScrollView | ||
| style={{ maxHeight: 88, flexGrow: 0 }} | ||
| contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 8 }} | ||
| > | ||
| <Text>{props.source}</Text> | ||
| </ScrollView> | ||
| ); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.valid( | ||
| "allows a style array whose last element resets the anchor to the edge", | ||
| ` | ||
| import { View } from "react-native"; | ||
|
|
||
| export function Overlay() { | ||
| return <View style={[{ position: "absolute", bottom: 16 }, { bottom: 0 }]} />; | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports an anchor split across style array elements", | ||
| ` | ||
| 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 an anchor guarded by a condition inside a style array", | ||
| ` | ||
| import { Pressable } from "react-native"; | ||
|
|
||
| export function ShowKeyboardButton(props: { readonly floating: boolean }) { | ||
| return ( | ||
| <Pressable | ||
| style={[{ right: 16 }, props.floating && { position: "absolute", bottom: 16 }]} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports an anchor on JSX rendered inside an array", | ||
| ` | ||
| import { View } from "react-native"; | ||
|
|
||
| export function Overlays() { | ||
| return [<View key="fab" style={{ position: "absolute", bottom: 16 }} />]; | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| rule.invalid( | ||
| "reports a screen-filling list sized with a percentage height", | ||
| ` | ||
| import { FlatList } from "react-native"; | ||
|
|
||
| export function FileList() { | ||
| return ( | ||
| <FlatList | ||
| data={[]} | ||
| renderItem={() => null} | ||
| style={{ height: "100%" }} | ||
| contentContainerStyle={{ paddingBottom: 8 }} | ||
| /> | ||
| ); | ||
| } | ||
| `, | ||
| (output) => { | ||
| assert.match(output, /safe-area inset/); | ||
| }, | ||
| ); | ||
|
|
||
| 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.