Use pressable for video controls (#5452)
* use pressable for video controls * add `as any` to preexisiting bad type * stop mutating prop
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'
|
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'
|
||||||
import {LayoutChangeEvent, ScrollView, StyleSheet, View} from 'react-native'
|
import {LayoutChangeEvent, ScrollView, StyleSheet, View} from 'react-native'
|
||||||
|
|
||||||
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
import {isNative} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
|
||||||
import {PressableWithHover} from '../util/PressableWithHover'
|
import {PressableWithHover} from '../util/PressableWithHover'
|
||||||
import {Text} from '../util/text/Text'
|
import {Text} from '../util/text/Text'
|
||||||
import {DraggableScrollView} from './DraggableScrollView'
|
import {DraggableScrollView} from './DraggableScrollView'
|
||||||
@@ -131,7 +131,7 @@ export function TabBar({
|
|||||||
<PressableWithHover
|
<PressableWithHover
|
||||||
testID={`${testID}-selector-${i}`}
|
testID={`${testID}-selector-${i}`}
|
||||||
key={`${item}-${i}`}
|
key={`${item}-${i}`}
|
||||||
ref={node => (itemRefs.current[i] = node)}
|
ref={node => (itemRefs.current[i] = node as any)}
|
||||||
onLayout={e => onItemLayout(e, i)}
|
onLayout={e => onItemLayout(e, i)}
|
||||||
style={styles.item}
|
style={styles.item}
|
||||||
hoverStyle={pal.viewLight}
|
hoverStyle={pal.viewLight}
|
||||||
|
|||||||
@@ -1,39 +1,35 @@
|
|||||||
import React, {
|
import React, {forwardRef, PropsWithChildren} from 'react'
|
||||||
useState,
|
|
||||||
useCallback,
|
|
||||||
PropsWithChildren,
|
|
||||||
forwardRef,
|
|
||||||
Ref,
|
|
||||||
} from 'react'
|
|
||||||
import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
|
import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
|
||||||
import {addStyle} from 'lib/styles'
|
import {View} from 'react-native'
|
||||||
|
|
||||||
|
import {addStyle} from '#/lib/styles'
|
||||||
|
import {useInteractionState} from '#/components/hooks/useInteractionState'
|
||||||
|
|
||||||
interface PressableWithHover extends PressableProps {
|
interface PressableWithHover extends PressableProps {
|
||||||
hoverStyle: StyleProp<ViewStyle>
|
hoverStyle: StyleProp<ViewStyle>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PressableWithHover = forwardRef(function PressableWithHoverImpl(
|
export const PressableWithHover = forwardRef<
|
||||||
{
|
View,
|
||||||
children,
|
PropsWithChildren<PressableWithHover>
|
||||||
style,
|
>(function PressableWithHoverImpl(
|
||||||
hoverStyle,
|
{children, style, hoverStyle, ...props},
|
||||||
...props
|
ref,
|
||||||
}: PropsWithChildren<PressableWithHover>,
|
|
||||||
ref: Ref<any>,
|
|
||||||
) {
|
) {
|
||||||
const [isHovering, setIsHovering] = useState(false)
|
const {
|
||||||
|
state: hovered,
|
||||||
const onHoverIn = useCallback(() => setIsHovering(true), [setIsHovering])
|
onIn: onHoverIn,
|
||||||
const onHoverOut = useCallback(() => setIsHovering(false), [setIsHovering])
|
onOut: onHoverOut,
|
||||||
style =
|
} = useInteractionState()
|
||||||
typeof style !== 'function' && isHovering
|
|
||||||
? addStyle(style, hoverStyle)
|
|
||||||
: style
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
{...props}
|
{...props}
|
||||||
style={style}
|
style={
|
||||||
|
typeof style !== 'function' && hovered
|
||||||
|
? addStyle(style, hoverStyle)
|
||||||
|
: style
|
||||||
|
}
|
||||||
onHoverIn={onHoverIn}
|
onHoverIn={onHoverIn}
|
||||||
onHoverOut={onHoverOut}
|
onHoverOut={onHoverOut}
|
||||||
ref={ref}>
|
ref={ref}>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {SvgProps} from 'react-native-svg'
|
import {SvgProps} from 'react-native-svg'
|
||||||
|
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme, web} from '#/alf'
|
||||||
import {Button} from '#/components/Button'
|
import {PressableWithHover} from '../../../PressableWithHover'
|
||||||
|
|
||||||
export function ControlButton({
|
export function ControlButton({
|
||||||
active,
|
active,
|
||||||
@@ -21,19 +21,21 @@ export function ControlButton({
|
|||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
return (
|
return (
|
||||||
<Button
|
<PressableWithHover
|
||||||
label={active ? activeLabel : inactiveLabel}
|
accessibilityRole="button"
|
||||||
|
accessibilityHint={active ? activeLabel : inactiveLabel}
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
variant="ghost"
|
style={[
|
||||||
shape="round"
|
a.p_xs,
|
||||||
size="large"
|
a.rounded_full,
|
||||||
style={a.p_2xs}
|
web({transition: 'background-color 0.1s'}),
|
||||||
hoverStyle={{backgroundColor: 'rgba(255, 255, 255, 0.1)'}}>
|
]}
|
||||||
|
hoverStyle={{backgroundColor: 'rgba(255, 255, 255, 0.2)'}}>
|
||||||
{active ? (
|
{active ? (
|
||||||
<ActiveIcon fill={t.palette.white} width={20} />
|
<ActiveIcon fill={t.palette.white} width={20} />
|
||||||
) : (
|
) : (
|
||||||
<InactiveIcon fill={t.palette.white} width={20} />
|
<InactiveIcon fill={t.palette.white} width={20} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</PressableWithHover>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,9 +358,8 @@ export function Controls({
|
|||||||
style={[
|
style={[
|
||||||
a.flex_1,
|
a.flex_1,
|
||||||
a.px_xs,
|
a.px_xs,
|
||||||
a.pt_2xs,
|
a.pb_sm,
|
||||||
a.pb_md,
|
a.gap_sm,
|
||||||
a.gap_md,
|
|
||||||
a.flex_row,
|
a.flex_row,
|
||||||
a.align_center,
|
a.align_center,
|
||||||
]}>
|
]}>
|
||||||
@@ -373,7 +372,11 @@ export function Controls({
|
|||||||
onPress={onPressPlayPause}
|
onPress={onPressPlayPause}
|
||||||
/>
|
/>
|
||||||
<View style={a.flex_1} />
|
<View style={a.flex_1} />
|
||||||
<Text style={{color: t.palette.white, fontVariant: ['tabular-nums']}}>
|
<Text
|
||||||
|
style={[
|
||||||
|
a.px_xs,
|
||||||
|
{color: t.palette.white, fontVariant: ['tabular-nums']},
|
||||||
|
]}>
|
||||||
{formatTime(currentTime)} / {formatTime(duration)}
|
{formatTime(currentTime)} / {formatTime(duration)}
|
||||||
</Text>
|
</Text>
|
||||||
{hasSubtitleTrack && (
|
{hasSubtitleTrack && (
|
||||||
|
|||||||
Reference in New Issue
Block a user