Repository navigation
feat(settle): prototype an adaptive early exit behind an internal switch (off by default) #4611
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
thymikee
wants to merge
8
commits into
main
Choose a base branch
from
t3/adaptive-settle-prototype
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.
+1,158
−41
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db668f1
test(test-app): add a settle lab of timed UI effects
thymikee 421179e
feat(settle): prototype an adaptive early exit behind an internal switch
thymikee c423b99
refactor(settle): keep the adaptive early exit off the eager closure …
thymikee 8d80138
fix(settle): escalate the adaptive early exit on a confirmed broad re…
thymikee 7442537
refactor(settle): leave the wait-target dedupe to its own change
thymikee 5b81888
fix(settle): escalate on a system-surface change and report the span …
thymikee 7dad132
test(test-app): acknowledge each settle lab effect at once and drop f…
thymikee 8142f91
fix(settle): hold the adaptive early exit while an armed latch has no…
thymikee 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { useLocalSearchParams } from 'expo-router'; | ||
|
|
||
| import { SettleLabResultScreen } from '../src/screens/SettleLabScreen'; | ||
|
|
||
| export default function SettleLabResultRoute() { | ||
| const { run } = useLocalSearchParams<{ run?: string }>(); | ||
| return <SettleLabResultScreen run={run} />; | ||
| } |
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,5 @@ | ||
| import { SettleLabScreen } from '../src/screens/SettleLabScreen'; | ||
|
|
||
| export default function SettleLabRoute() { | ||
| return <SettleLabScreen />; | ||
| } |
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,191 @@ | ||
| import { router } from 'expo-router'; | ||
| import { useEffect, useRef, useState } from 'react'; | ||
| import { ActivityIndicator, Animated, Pressable, StyleSheet, Text, View } from 'react-native'; | ||
|
|
||
| /** | ||
| * Timed UI effects for measuring `--settle`: each button starts one effect whose final screen is | ||
| * known, so a settled tree can be checked against it. `settle-run` acknowledges each effect at once, | ||
| * the way an app shows a pending state, and `settle-status` names the final state of the last effect | ||
| * with its run number. | ||
| */ | ||
| const DELAYS_MS = [500, 800] as const; | ||
| const FADE_MS = 750; | ||
| const STAGE_MS = 600; | ||
| const NAVIGATE_AFTER_TOAST_MS = 700; | ||
|
|
||
| export function SettleLabScreen() { | ||
| const [run, setRun] = useState(0); | ||
| const [count, setCount] = useState(0); | ||
| const [status, setStatus] = useState('idle'); | ||
| const [stage, setStage] = useState<'none' | 'spinner' | 'plain'>('none'); | ||
| const [overlayVisible, setOverlayVisible] = useState(false); | ||
| const [toast, setToast] = useState<string | null>(null); | ||
| const opacity = useRef(new Animated.Value(1)).current; | ||
| const timers = useRef<ReturnType<typeof setTimeout>[]>([]); | ||
|
|
||
| useEffect(() => () => timers.current.forEach(clearTimeout), []); | ||
|
|
||
| const later = (ms: number, effect: () => void) => { | ||
| const handle = setTimeout(() => { | ||
| timers.current = timers.current.filter((pending) => pending !== handle); | ||
| effect(); | ||
| }, ms); | ||
| timers.current.push(handle); | ||
| }; | ||
| const nextRun = () => { | ||
| const next = run + 1; | ||
| setRun(next); | ||
| return next; | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={styles.frame} testID="settle-lab-root"> | ||
| <Text style={styles.title}>Settle lab</Text> | ||
| <Text style={styles.status} testID="settle-status"> | ||
| {status} | ||
| </Text> | ||
| <Text style={styles.status} testID="settle-count"> | ||
| {`Count ${count}`} | ||
| </Text> | ||
| <Text style={styles.status} testID="settle-run"> | ||
| {`Run ${run}`} | ||
| </Text> | ||
| <LabButton id="settle-increment" label="Increment" onPress={() => setCount((c) => c + 1)} /> | ||
| {DELAYS_MS.map((delayMs) => ( | ||
| <LabButton | ||
| id={`settle-delay-${delayMs}`} | ||
| key={delayMs} | ||
| label={`Delay ${delayMs}`} | ||
| onPress={() => { | ||
| const id = nextRun(); | ||
| later(delayMs, () => setStatus(`Delayed ${delayMs} done ${id}`)); | ||
| }} | ||
| /> | ||
| ))} | ||
| <LabButton | ||
| id="settle-overlay" | ||
| label="Fade overlay" | ||
| onPress={() => { | ||
| const id = nextRun(); | ||
| opacity.setValue(1); | ||
| setOverlayVisible(true); | ||
| Animated.timing(opacity, { | ||
| toValue: 0, | ||
| duration: FADE_MS, | ||
| useNativeDriver: true, | ||
| }).start(() => { | ||
| setOverlayVisible(false); | ||
| setStatus(`Overlay gone ${id}`); | ||
| }); | ||
| }} | ||
| /> | ||
| <LabButton | ||
| id="settle-two-stage-spinner" | ||
| label="Two stage spinner" | ||
| onPress={() => { | ||
| const id = nextRun(); | ||
| setStage('spinner'); | ||
| later(STAGE_MS, () => { | ||
| setStage('none'); | ||
| setStatus(`Stage done ${id}`); | ||
| }); | ||
| }} | ||
| /> | ||
| <LabButton | ||
| id="settle-two-stage-plain" | ||
| label="Two stage plain" | ||
| onPress={() => { | ||
| const id = nextRun(); | ||
| setStage('plain'); | ||
| later(STAGE_MS, () => { | ||
| setStage('none'); | ||
| setStatus(`Stage done ${id}`); | ||
| }); | ||
| }} | ||
| /> | ||
| <LabButton | ||
| id="settle-toast-navigate" | ||
| label="Toast then navigate" | ||
| onPress={() => { | ||
| const id = nextRun(); | ||
| setToast('Saving'); | ||
| later(NAVIGATE_AFTER_TOAST_MS, () => { | ||
| setToast(null); | ||
| router.push({ pathname: '/settle-lab-result', params: { run: String(id) } }); | ||
| }); | ||
| }} | ||
| /> | ||
| {stage === 'spinner' ? ( | ||
| <View style={styles.row} testID="settle-stage-spinner"> | ||
| <ActivityIndicator /> | ||
| <Text style={styles.status}>Working</Text> | ||
| </View> | ||
| ) : null} | ||
| {stage === 'plain' ? ( | ||
| <Text style={styles.status} testID="settle-stage-plain"> | ||
| Step 1 of 2 | ||
| </Text> | ||
| ) : null} | ||
| {toast ? ( | ||
| <View style={styles.toast} testID="settle-toast"> | ||
| <Text style={styles.toastLabel}>{toast}</Text> | ||
| </View> | ||
| ) : null} | ||
| {overlayVisible ? ( | ||
| <Animated.View style={[styles.overlay, { opacity }]} testID="settle-overlay-panel"> | ||
| <Pressable accessibilityRole="button" style={styles.overlayButton}> | ||
| <Text style={styles.toastLabel}>Overlay</Text> | ||
| </Pressable> | ||
| </Animated.View> | ||
| ) : null} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export function SettleLabResultScreen({ run }: { run: string | undefined }) { | ||
| return ( | ||
| <View style={styles.frame} testID="settle-lab-result"> | ||
| <Text style={styles.title}>{`Result ${run ?? ''}`}</Text> | ||
| <LabButton id="settle-result-back" label="Back to lab" onPress={() => router.back()} /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function LabButton(props: { id: string; label: string; onPress: () => void }) { | ||
| return ( | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| onPress={props.onPress} | ||
| style={styles.button} | ||
| testID={props.id} | ||
| > | ||
| <Text style={styles.buttonLabel}>{props.label}</Text> | ||
| </Pressable> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| frame: { flex: 1, gap: 8, padding: 24, paddingTop: 72, backgroundColor: '#fff' }, | ||
| title: { fontSize: 24, fontWeight: '700' }, | ||
| status: { fontSize: 16 }, | ||
| row: { flexDirection: 'row', gap: 8, alignItems: 'center' }, | ||
| button: { backgroundColor: '#e8eefc', borderRadius: 8, padding: 12 }, | ||
| buttonLabel: { fontSize: 16 }, | ||
| toast: { | ||
| position: 'absolute', | ||
| bottom: 48, | ||
| left: 24, | ||
| right: 24, | ||
| backgroundColor: '#222', | ||
| borderRadius: 8, | ||
| padding: 12, | ||
| }, | ||
| toastLabel: { color: '#fff', fontSize: 16 }, | ||
| overlay: { | ||
| ...StyleSheet.absoluteFill, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| backgroundColor: 'rgba(0,0,0,0.5)', | ||
| }, | ||
| overlayButton: { backgroundColor: '#333', borderRadius: 8, padding: 24 }, | ||
| }); | ||
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
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.