import React, { useMemo } from 'react'; import { Pressable, StyleProp, StyleSheet, Text, ViewStyle } from 'react-native'; import { useTheme } from '../../contexts/themeContext/ThemeContext'; import { primitives } from '../../theme'; export type SpeedSettingsButtonProps = { /** * The current playback rate. */ currentPlaybackRate: number; /** * The function to be called when the button is pressed. */ onPress: () => void; /** * The style of the container. */ containerStyle?: StyleProp; }; export const SpeedSettingsButton = ({ currentPlaybackRate, onPress, containerStyle, }: SpeedSettingsButtonProps) => { const styles = useStyles(); const { theme: { semantics }, } = useTheme(); return ( [ styles.container, { backgroundColor: pressed ? semantics.backgroundUtilityPressed : 'transparent', }, containerStyle, ]} > {`x${currentPlaybackRate.toFixed(1)}`} ); }; const useStyles = () => { const { theme: { semantics }, } = useTheme(); return useMemo(() => { return StyleSheet.create({ container: { borderRadius: primitives.radiusMax, height: 24, width: 40, justifyContent: 'center', alignItems: 'center', borderWidth: 1, borderColor: semantics.controlPlaybackToggleBorder, }, text: { color: semantics.controlPlaybackToggleText, fontSize: primitives.typographyFontSizeXs, fontWeight: primitives.typographyFontWeightSemiBold, lineHeight: primitives.typographyLineHeightTight, }, }); }, [semantics]); };