mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
feat(mobile): show a thin refresh line under the header while cached data refreshes (#39170)
* feat(mobile): show a thin refresh line under the header while cached data refreshes * fix(mobile): start the refresh line still under unknown motion and key it by execution host * fix(mobile): draw the refresh line only once the motion preference is known * fix(mobile): start the refresh sweep at the left edge on each reveal * refactor(mobile): drive the refresh line from the screen's own refetch and keep its timers in the header * test(mobile): give the Changes content fixture the new refreshing field
This commit is contained in:
@@ -9,9 +9,11 @@ import {
|
||||
type ViewStyle
|
||||
} from 'react-native'
|
||||
import { ChevronDown } from 'lucide-react-native'
|
||||
import { useReducedMotionEnabled } from '../../platform/use-reduced-motion'
|
||||
import { colors, pressedStyle, spacing } from '../../theme/mobile-theme'
|
||||
import { themedStyleSheet } from '../../theme/themed-styles'
|
||||
import { useMobileColorScheme } from '../../theme/use-mobile-color-scheme'
|
||||
import { useWorkingSweep } from '../use-working-motion'
|
||||
|
||||
export const NAV_BAR_HEIGHT = 52
|
||||
|
||||
@@ -31,6 +33,8 @@ type NavBarProps = {
|
||||
/** From useCollapsingTitle: the title waits until the list's PageTitle has scrolled under the bar. */
|
||||
titleOpacity?: Animated.AnimatedInterpolation<number>
|
||||
dividerOpacity?: Animated.AnimatedInterpolation<number>
|
||||
/** From useRefreshHint: shown data is refreshing in the background. */
|
||||
refreshing?: boolean
|
||||
}
|
||||
|
||||
// The one top bar: leading button, a centred compact title, and up to two trailing buttons.
|
||||
@@ -43,7 +47,8 @@ export function NavBar({
|
||||
accessory,
|
||||
style,
|
||||
titleOpacity,
|
||||
dividerOpacity
|
||||
dividerOpacity,
|
||||
refreshing = false
|
||||
}: NavBarProps) {
|
||||
useMobileColorScheme()
|
||||
return (
|
||||
@@ -78,6 +83,31 @@ export function NavBar({
|
||||
{dividerOpacity ? (
|
||||
<Animated.View pointerEvents="none" style={[styles.divider, { opacity: dividerOpacity }]} />
|
||||
) : null}
|
||||
{refreshing ? <NavBarRefreshLine /> : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
// Sits on the bar's bottom edge so the title, subtitle and accessory never move.
|
||||
function NavBarRefreshLine() {
|
||||
const reducedMotion = useReducedMotionEnabled()
|
||||
const sweep = useWorkingSweep(reducedMotion === false)
|
||||
// Draw nothing until the preference is known, so a reveal never swaps shapes.
|
||||
if (reducedMotion === null) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
accessibilityElementsHidden
|
||||
importantForAccessibility="no-hide-descendants"
|
||||
style={styles.refreshTrack}
|
||||
>
|
||||
<Animated.View
|
||||
ref={sweep.ref}
|
||||
onLayout={sweep.onLayout}
|
||||
style={[styles.refreshSegment, reducedMotion ? styles.refreshSegmentStill : sweep.style]}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -154,6 +184,24 @@ const styles = themedStyleSheet(() => ({
|
||||
height: StyleSheet.hairlineWidth,
|
||||
backgroundColor: colors.borderSubtle
|
||||
},
|
||||
refreshTrack: {
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: -StyleSheet.hairlineWidth,
|
||||
height: 2,
|
||||
overflow: 'hidden'
|
||||
},
|
||||
refreshSegment: {
|
||||
width: '28%',
|
||||
height: '100%',
|
||||
borderRadius: 1,
|
||||
backgroundColor: colors.textSecondary
|
||||
},
|
||||
refreshSegmentStill: {
|
||||
width: '100%',
|
||||
opacity: 0.45
|
||||
},
|
||||
// Equal sides keep the title centred whatever the buttons on either side.
|
||||
side: {
|
||||
flex: 1,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { Animated, Easing } from 'react-native'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Animated, Easing, type LayoutChangeEvent } from 'react-native'
|
||||
|
||||
// The page runs these as compositor animations instead (use-working-motion.web.ts).
|
||||
export type WorkingMotion<Style> = { ref: (node: unknown) => void; style: Style | undefined }
|
||||
@@ -54,3 +54,47 @@ export function useWorkingPulse(active: boolean): WorkingMotion<{ opacity: Anima
|
||||
}, [active, opacity])
|
||||
return { ref: noRef, style: { opacity } }
|
||||
}
|
||||
|
||||
// In segment widths, like the page's percent keyframes; ends past the track's right edge.
|
||||
const SWEEP_END = 3.6
|
||||
|
||||
/** A busy line's segment sweeping across its track; transforms can't animate percents natively, so it measures itself. */
|
||||
export function useWorkingSweep(active: boolean): WorkingMotion<{
|
||||
opacity: number
|
||||
transform: { translateX: Animated.AnimatedInterpolation<number> }[]
|
||||
}> & { onLayout: ((event: LayoutChangeEvent) => void) | undefined } {
|
||||
const progress = useRef(new Animated.Value(0)).current
|
||||
const [segmentWidth, setSegmentWidth] = useState(0)
|
||||
useEffect(() => {
|
||||
if (!active) {
|
||||
progress.setValue(0)
|
||||
return undefined
|
||||
}
|
||||
const animation = Animated.loop(
|
||||
Animated.timing(progress, {
|
||||
toValue: 1,
|
||||
duration: 1400,
|
||||
easing: Easing.bezier(0.45, 0, 0.55, 1),
|
||||
isInteraction: false,
|
||||
useNativeDriver: true
|
||||
})
|
||||
)
|
||||
animation.start()
|
||||
return () => animation.stop()
|
||||
}, [active, progress])
|
||||
// A new node per render would re-attach to the native loop each time.
|
||||
const translateX = useMemo(
|
||||
() =>
|
||||
progress.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [-segmentWidth, segmentWidth * SWEEP_END]
|
||||
}),
|
||||
[progress, segmentWidth]
|
||||
)
|
||||
return {
|
||||
ref: noRef,
|
||||
// Unmeasured, it would sit still at the left edge for a frame.
|
||||
style: { opacity: segmentWidth === 0 ? 0 : 1, transform: [{ translateX }] },
|
||||
onLayout: (event) => setSegmentWidth(event.nativeEvent.layout.width)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ import type { WorkingMotion } from './use-working-motion'
|
||||
function useElementLoop(
|
||||
active: boolean,
|
||||
keyframes: Keyframe[],
|
||||
options: KeyframeAnimationOptions
|
||||
options: KeyframeAnimationOptions,
|
||||
sharePhase = true
|
||||
): (node: unknown) => void {
|
||||
const [element, setElement] = useState<HTMLElement | null>(null)
|
||||
const ref = useCallback(
|
||||
@@ -18,9 +19,11 @@ function useElementLoop(
|
||||
return undefined
|
||||
}
|
||||
const animation = element.animate(keyframes, { ...options, iterations: Infinity })
|
||||
animation.startTime = 0
|
||||
if (sharePhase) {
|
||||
animation.startTime = 0
|
||||
}
|
||||
return () => animation.cancel()
|
||||
}, [active, element, keyframes, options])
|
||||
}, [active, element, keyframes, options, sharePhase])
|
||||
return ref
|
||||
}
|
||||
|
||||
@@ -34,6 +37,11 @@ const PULSE: Keyframe[] = [
|
||||
{ opacity: 1 }
|
||||
]
|
||||
const PULSE_TIMING: KeyframeAnimationOptions = { duration: 2000 }
|
||||
const SWEEP: Keyframe[] = [{ transform: 'translateX(-100%)' }, { transform: 'translateX(360%)' }]
|
||||
const SWEEP_TIMING: KeyframeAnimationOptions = {
|
||||
duration: 1400,
|
||||
easing: 'cubic-bezier(0.45, 0, 0.55, 1)'
|
||||
}
|
||||
|
||||
export function useWorkingRingRotation(active: boolean): WorkingMotion<never> {
|
||||
return { ref: useElementLoop(active, SPIN, SPIN_TIMING), style: undefined }
|
||||
@@ -42,3 +50,13 @@ export function useWorkingRingRotation(active: boolean): WorkingMotion<never> {
|
||||
export function useWorkingPulse(active: boolean): WorkingMotion<never> {
|
||||
return { ref: useElementLoop(active, PULSE, PULSE_TIMING), style: undefined }
|
||||
}
|
||||
|
||||
// Percent keyframes follow the segment's own width, so the page needs no layout pass.
|
||||
// Each reveal starts at the left edge: a shared phase could show a short reveal only as it exits right.
|
||||
export function useWorkingSweep(active: boolean): WorkingMotion<never> & { onLayout: undefined } {
|
||||
return {
|
||||
ref: useElementLoop(active, SWEEP, SWEEP_TIMING, false),
|
||||
style: undefined,
|
||||
onLayout: undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
CALM_STATUS_IDLE,
|
||||
stepCalmStatusReveal,
|
||||
type CalmStatusReveal,
|
||||
type CalmStatusSchedule
|
||||
} from '../../../src/shared/calm-status-reveal'
|
||||
|
||||
// Quick revalidations never show, and a shown hint never flashes.
|
||||
const REFRESH_HINT_SCHEDULE: CalmStatusSchedule = {
|
||||
revealDelayMs: 400,
|
||||
minVisibleMs: 400,
|
||||
healthyHoldMs: 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to show the header's refresh line. Pass `isRefetching` of the queries the screen shows:
|
||||
* it is false while a screen has no data (that screen spins instead), and stream-backed queries never fetch.
|
||||
*/
|
||||
export function useRefreshHint(refetching: boolean): boolean {
|
||||
const revealRef = useRef<CalmStatusReveal>(CALM_STATUS_IDLE)
|
||||
const [visible, setVisible] = useState(false)
|
||||
useEffect(() => {
|
||||
const step = (): void => {
|
||||
const next = stepCalmStatusReveal(
|
||||
revealRef.current,
|
||||
{ down: refetching, immediate: false, now: Date.now() },
|
||||
REFRESH_HINT_SCHEDULE
|
||||
)
|
||||
revealRef.current = next.next
|
||||
setVisible(next.visible)
|
||||
if (next.recheckInMs !== null) {
|
||||
timer = setTimeout(step, Math.max(0, next.recheckInMs))
|
||||
}
|
||||
}
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
step()
|
||||
return () => clearTimeout(timer)
|
||||
}, [refetching])
|
||||
return visible
|
||||
}
|
||||
@@ -136,6 +136,7 @@ function initialState(): MobileSourceControlContentState {
|
||||
connState: 'connected',
|
||||
forceReconnect: null,
|
||||
rebaseBaseRef: 'main',
|
||||
refreshing: false,
|
||||
insets: { top: 0, bottom: 0, left: 0, right: 0 },
|
||||
router: {
|
||||
back: noop,
|
||||
|
||||
@@ -6,11 +6,14 @@ import type { ActionSheetAction } from '../components/ActionSheetModal'
|
||||
import { NavBar } from '../components/nav-bar/NavBar'
|
||||
import { NavBarButton } from '../components/nav-bar/NavBarButton'
|
||||
import { PullDownMenu } from '../components/nav-bar/PullDownMenu'
|
||||
import { useRefreshHint } from '../query/refresh-hint'
|
||||
|
||||
type Props = {
|
||||
embedded: boolean
|
||||
worktreeLabel: string
|
||||
ioBusy: boolean
|
||||
/** Shown rows are being re-read; the line waits out quick reads. */
|
||||
refreshing: boolean
|
||||
onBack: () => void
|
||||
// Dock dismissal does not pop a route; keep it separate from Back.
|
||||
onClose: () => void
|
||||
@@ -28,6 +31,7 @@ export function MobileSourceControlHeader({
|
||||
embedded,
|
||||
worktreeLabel,
|
||||
ioBusy,
|
||||
refreshing,
|
||||
onBack,
|
||||
onClose,
|
||||
onRefresh,
|
||||
@@ -37,6 +41,8 @@ export function MobileSourceControlHeader({
|
||||
menuGroups = null
|
||||
}: Props) {
|
||||
const t = useMobileTranslation()
|
||||
// Here, not in the panel, so the hint's timers re-render only the bar.
|
||||
const showRefreshLine = useRefreshHint(refreshing)
|
||||
const moreRef = useRef<View>(null)
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
const actions: ActionSheetAction[] = [
|
||||
@@ -88,6 +94,7 @@ export function MobileSourceControlHeader({
|
||||
title={t('sourceControl.header.title', 'Source Control')}
|
||||
subtitle={worktreeLabel}
|
||||
accessory={accessory}
|
||||
refreshing={showRefreshLine}
|
||||
trailing={
|
||||
<NavBarButton
|
||||
ref={moreRef}
|
||||
|
||||
@@ -278,6 +278,8 @@ export function MobileSourceControlPanel({
|
||||
embedded={embedded}
|
||||
worktreeLabel={worktreeLabel}
|
||||
ioBusy={ioBusy}
|
||||
// Only Changes reads through the query layer so far; the PR tab keeps its own loading UI.
|
||||
refreshing={activeTab === 'changes' && state.refreshing}
|
||||
onBack={onBack}
|
||||
onClose={onClose}
|
||||
onRefresh={onRefresh}
|
||||
|
||||
@@ -60,6 +60,8 @@ export type MobileSourceControlLoaders = {
|
||||
mountedRef: MutableRefObject<boolean>
|
||||
setRootRef: (node: View | null) => void
|
||||
loadStatus: (options?: LoadStatusOptions) => Promise<boolean>
|
||||
// Shown rows are being re-read; feeds the header's refresh line.
|
||||
refreshing: boolean
|
||||
settings: MobileSourceControlSettings
|
||||
// Desktop's rebase target; kept apart from the compare so a failed or unsupported compare keeps it.
|
||||
rebaseBaseRef: string | null
|
||||
@@ -292,6 +294,7 @@ export function useMobileSourceControlLoaders(params: Params): MobileSourceContr
|
||||
mountedRef,
|
||||
setRootRef,
|
||||
loadStatus,
|
||||
refreshing: statusQuery.isRefetching,
|
||||
settings,
|
||||
rebaseBaseRef
|
||||
}
|
||||
|
||||
@@ -243,6 +243,7 @@ export function useMobileSourceControlState(params: MobileSourceControlStatePara
|
||||
createPrAction,
|
||||
loadStatus,
|
||||
rebaseBaseRef: loaders.rebaseBaseRef,
|
||||
refreshing: loaders.refreshing,
|
||||
openDiffForFile,
|
||||
...runners
|
||||
}
|
||||
|
||||
@@ -9,6 +9,18 @@ export const CALM_STATUS_MIN_VISIBLE_MS = 2_000
|
||||
// A quick redrop remains part of the same outage.
|
||||
export const CALM_STATUS_HEALTHY_HOLD_MS = 1_000
|
||||
|
||||
export type CalmStatusSchedule = {
|
||||
revealDelayMs: number
|
||||
minVisibleMs: number
|
||||
healthyHoldMs: number
|
||||
}
|
||||
|
||||
const CALM_STATUS_SCHEDULE: CalmStatusSchedule = {
|
||||
revealDelayMs: CALM_STATUS_REVEAL_DELAY_MS,
|
||||
minVisibleMs: CALM_STATUS_MIN_VISIBLE_MS,
|
||||
healthyHoldMs: CALM_STATUS_HEALTHY_HOLD_MS
|
||||
}
|
||||
|
||||
export type CalmStatusReveal = {
|
||||
downSince: number | null
|
||||
shownAt: number | null
|
||||
@@ -36,18 +48,19 @@ export function stepCalmStatusReveal(
|
||||
now: number
|
||||
/** An outage start another observer already saw; the clock continues from it. */
|
||||
since?: number | null
|
||||
}
|
||||
},
|
||||
schedule: CalmStatusSchedule = CALM_STATUS_SCHEDULE
|
||||
): CalmStatusStep {
|
||||
const { now } = input
|
||||
if (input.down) {
|
||||
const downSince = previous.downSince ?? Math.min(input.since ?? now, now)
|
||||
const shownAt =
|
||||
previous.shownAt ??
|
||||
(input.immediate || now - downSince >= CALM_STATUS_REVEAL_DELAY_MS ? now : null)
|
||||
(input.immediate || now - downSince >= schedule.revealDelayMs ? now : null)
|
||||
return {
|
||||
next: { downSince, shownAt, healthySince: null },
|
||||
visible: shownAt !== null,
|
||||
recheckInMs: shownAt === null ? downSince + CALM_STATUS_REVEAL_DELAY_MS - now : null
|
||||
recheckInMs: shownAt === null ? downSince + schedule.revealDelayMs - now : null
|
||||
}
|
||||
}
|
||||
if (previous.downSince === null) {
|
||||
@@ -55,8 +68,8 @@ export function stepCalmStatusReveal(
|
||||
}
|
||||
const healthySince = previous.healthySince ?? now
|
||||
const hideAt = Math.max(
|
||||
healthySince + CALM_STATUS_HEALTHY_HOLD_MS,
|
||||
previous.shownAt === null ? 0 : previous.shownAt + CALM_STATUS_MIN_VISIBLE_MS
|
||||
healthySince + schedule.healthyHoldMs,
|
||||
previous.shownAt === null ? 0 : previous.shownAt + schedule.minVisibleMs
|
||||
)
|
||||
if (now >= hideAt) {
|
||||
return { next: CALM_STATUS_IDLE, visible: false, recheckInMs: null }
|
||||
|
||||
Reference in New Issue
Block a user