Repository navigation
fix(mobile): remove tab control flicker on iOS PR screen #27269
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
Closed
intergalacticspacehighway
wants to merge
2
commits into
pingdotgg:main
from
intergalacticspacehighway:fix/mobile-ios-pr-tab-double-indicator
+185
−17
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
121 changes: 121 additions & 0 deletions
121
apps/mobile/src/features/pull-requests/PullRequestTabControl.ios.tsx
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,121 @@ | ||
| import { useRef, useState } from "react"; | ||
| import { StyleSheet, View } from "react-native"; | ||
| import Animated, { | ||
| runOnJS, | ||
| useAnimatedReaction, | ||
| useAnimatedStyle, | ||
| useDerivedValue, | ||
| useSharedValue, | ||
| } from "react-native-reanimated"; | ||
|
|
||
| import { SegmentedControl } from "../../components/ui/SegmentedControl"; | ||
| import type { PullRequestTabControl, PullRequestTabControlProps } from "./PullRequestTabControl"; | ||
|
|
||
| export type { | ||
| PullRequestSection, | ||
| PullRequestTabControl, | ||
| PullRequestTabControlProps, | ||
| } from "./PullRequestTabControl"; | ||
|
|
||
| // The screen keeps one list per tab, and a control in each list header. When the tapped control's | ||
| // list hides, UIKit keeps drawing its glass lens over the next list's control. So one control | ||
| // above the lists takes the taps and follows the shown list's scroll. Under the bar, the header | ||
| // copies take over, so the scroll edge effect still covers the control. | ||
| export function usePullRequestTabControl(props: PullRequestTabControlProps): PullRequestTabControl { | ||
| const overviewScroll = useSharedValue(0); | ||
| const guideScroll = useSharedValue(0); | ||
| const activityScroll = useSharedValue(0); | ||
| const [listScroll] = useState(() => ({ | ||
| overview: { scrollOffset: overviewScroll }, | ||
| guide: { scrollOffset: guideScroll }, | ||
| activity: { scrollOffset: activityScroll }, | ||
| })); | ||
| const layout = useRef<{ header?: number; control?: number }>({}); | ||
| // A shared value, not state, so a header layout change moves the control without a re-render. | ||
| const controlY = useSharedValue<number | null>(null); | ||
| // The two onLayout events can arrive in either order. Until both have, the header copy shows. | ||
| const measure = () => { | ||
| const { header, control } = layout.current; | ||
| if (header !== undefined && control !== undefined) { | ||
| controlY.set(props.listPaddingTop + header + control); | ||
| } | ||
| }; | ||
| const shownScroll = listScroll[props.selected].scrollOffset; | ||
| const { barInsetTop } = props; | ||
| const underBar = useDerivedValue( | ||
| () => controlY.value === null || controlY.value - shownScroll.value < barInsetTop, | ||
| ); | ||
| const overlayStyle = useAnimatedStyle(() => ({ | ||
| opacity: underBar.value ? 0 : 1, | ||
| transform: [{ translateY: (controlY.value ?? 0) - shownScroll.value }], | ||
| })); | ||
| const headerStyle = useAnimatedStyle(() => ({ opacity: underBar.value ? 1 : 0 })); | ||
| // Touch follows whichever copy shows. It changes only when the control crosses the bar, so | ||
| // the JS state does not update while scrolling. | ||
| const [headerShown, setHeaderShown] = useState(true); | ||
| useAnimatedReaction( | ||
| () => underBar.value, | ||
| (shown, previous) => { | ||
| if (shown !== previous) runOnJS(setHeaderShown)(shown); | ||
| }, | ||
| ); | ||
| const control = ( | ||
| <SegmentedControl | ||
| options={props.options} | ||
| selected={props.selected} | ||
| onSelect={props.onSelect} | ||
| role="tab" | ||
| size="compact" | ||
| /> | ||
| ); | ||
| return { | ||
| listSharedValues: (section) => listScroll[section], | ||
| onHeaderLayout: (y) => { | ||
| layout.current.header = y; | ||
| measure(); | ||
| }, | ||
| header: ( | ||
| <View | ||
| onLayout={(event) => { | ||
| layout.current.control = event.nativeEvent.layout.y; | ||
| measure(); | ||
| }} | ||
| > | ||
| <Animated.View | ||
| style={headerStyle} | ||
| pointerEvents={headerShown ? "auto" : "none"} | ||
| accessibilityElementsHidden | ||
| > | ||
| {control} | ||
| </Animated.View> | ||
| {/* VoiceOver skips views at opacity 0 and reads the overlay after the lists, so these | ||
| invisible tabs keep the reading order. Their taps land on the control under them. */} | ||
| <View | ||
| style={StyleSheet.absoluteFill} | ||
| className="flex-row" | ||
| pointerEvents="none" | ||
| accessibilityRole="tabbar" | ||
| > | ||
| {props.options.map((option) => ( | ||
| <View | ||
| key={option.value} | ||
| className="flex-1" | ||
| accessible | ||
| accessibilityRole="tab" | ||
| accessibilityLabel={option.label} | ||
| accessibilityState={{ selected: option.value === props.selected }} | ||
| /> | ||
| ))} | ||
| </View> | ||
| </View> | ||
| ), | ||
| overlay: ( | ||
| <Animated.View | ||
| style={[{ position: "absolute", top: 0, left: 16, right: 16 }, overlayStyle]} | ||
| accessibilityElementsHidden | ||
| > | ||
| {control} | ||
| </Animated.View> | ||
| ), | ||
| }; | ||
| } |
46 changes: 46 additions & 0 deletions
46
apps/mobile/src/features/pull-requests/PullRequestTabControl.tsx
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,46 @@ | ||
| import type { AnimatedLegendListSharedValues } from "@legendapp/list/reanimated"; | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| import { SegmentedControl } from "../../components/ui/SegmentedControl"; | ||
|
|
||
| export type PullRequestSection = "overview" | "guide" | "activity"; | ||
|
|
||
| export interface PullRequestTabControlProps { | ||
| readonly options: readonly { readonly value: PullRequestSection; readonly label: string }[]; | ||
| readonly selected: PullRequestSection; | ||
| readonly onSelect: (section: PullRequestSection) => void; | ||
| /** Top inset the lists scroll under. */ | ||
| readonly barInsetTop: number; | ||
| /** Top padding of each list's content container. */ | ||
| readonly listPaddingTop: number; | ||
| } | ||
|
|
||
| export interface PullRequestTabControl { | ||
| readonly listSharedValues: ( | ||
| section: PullRequestSection, | ||
| ) => AnimatedLegendListSharedValues | undefined; | ||
| /** Reports the y of the list header view that holds `header`. */ | ||
| readonly onHeaderLayout: (y: number) => void; | ||
| /** Goes in each list header. */ | ||
| readonly header: ReactNode; | ||
| /** Goes above the lists. */ | ||
| readonly overlay: ReactNode; | ||
| } | ||
|
|
||
| // oxlint-disable-next-line t3code/no-hookless-use-function -- Non-iOS stub of a hook; the .ios.tsx file calls hooks. | ||
| export function usePullRequestTabControl(props: PullRequestTabControlProps): PullRequestTabControl { | ||
| return { | ||
| listSharedValues: () => undefined, | ||
| onHeaderLayout: () => {}, | ||
| header: ( | ||
| <SegmentedControl | ||
| options={props.options} | ||
| selected={props.selected} | ||
| onSelect={props.onSelect} | ||
| role="tab" | ||
| size="compact" | ||
| /> | ||
| ), | ||
| overlay: null, | ||
| }; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: pingdotgg/t3code
Length of output: 41879
Script executed:
Repository: pingdotgg/t3code
Length of output: 43130
Script executed:
Repository: pingdotgg/t3code
Length of output: 13245
Wire VoiceOver activation to the tab handler.
The iOS fallback tabs are readable but not actionable. The actual
SegmentedControlinstances are hidden from accessibility, while the replacementViewelements have no activation callback. VoiceOver users can focus each tab, but activating it does not callselectSection, so the visible section does not change.Suggested fix
accessibilityRole="tab" accessibilityLabel={option.label} accessibilityState={{ selected: option.value === props.selected }} + onAccessibilityTap={() => props.onSelect(option.value)} />