feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -100,11 +100,12 @@ export function WaveBars({
|
|||
)
|
||||
return () => {
|
||||
mounted = false
|
||||
subscription.remove()
|
||||
subscription?.remove?.()
|
||||
}
|
||||
}, [reduceMotion])
|
||||
|
||||
const motionDisabled = reduceMotion ?? systemReduceMotion
|
||||
const safeBarCount = Number.isFinite(barCount) ? Math.max(0, Math.floor(barCount)) : 11
|
||||
const containerStyle: ViewStyle = {
|
||||
height: 128,
|
||||
backgroundColor: palette.bg.inset,
|
||||
|
|
@ -118,7 +119,7 @@ export function WaveBars({
|
|||
|
||||
return (
|
||||
<View style={[containerStyle, style]}>
|
||||
{Array.from({ length: barCount }).map((_, i) => (
|
||||
{Array.from({ length: safeBarCount }).map((_, i) => (
|
||||
<WaveBar
|
||||
key={i}
|
||||
index={i}
|
||||
|
|
|
|||
|
|
@ -34,3 +34,19 @@ export { PhysicalButton, type PhysicalButtonProps } from './components/PhysicalB
|
|||
export { ScreenPanel, type ScreenPanelProps } from './components/ScreenPanel'
|
||||
export { WaveBars, type WaveBarsProps } from './components/WaveBars'
|
||||
export { FilterChip, type FilterChipProps } from './components/FilterChip'
|
||||
export {
|
||||
TABLET_BREAKPOINT_DP,
|
||||
CONTENT_MAX_WIDTH_DP,
|
||||
WIDE_CONTENT_MAX_WIDTH_DP,
|
||||
FORM_MAX_WIDTH_DP,
|
||||
ACTION_BUTTON_MAX_WIDTH_DP,
|
||||
PHONE_BANNER_MIN_HEIGHT_DP,
|
||||
TABLET_BANNER_MIN_HEIGHT_DP,
|
||||
resolveResponsiveLayout,
|
||||
useResponsiveLayout,
|
||||
useContentWidth,
|
||||
ContentColumn,
|
||||
type ContentColumnProps,
|
||||
type ContentColumnVariant,
|
||||
type ResponsiveLayoutMetrics
|
||||
} from './responsive'
|
||||
|
|
|
|||
96
packages/ui-native/src/responsive.tsx
Normal file
96
packages/ui-native/src/responsive.tsx
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import React from 'react'
|
||||
import { StyleSheet, View, useWindowDimensions, type StyleProp, type ViewStyle } from 'react-native'
|
||||
|
||||
export const TABLET_BREAKPOINT_DP = 600
|
||||
export const CONTENT_MAX_WIDTH_DP = 720
|
||||
export const WIDE_CONTENT_MAX_WIDTH_DP = 960
|
||||
export const FORM_MAX_WIDTH_DP = 480
|
||||
export const ACTION_BUTTON_MAX_WIDTH_DP = 320
|
||||
export const PHONE_BANNER_MIN_HEIGHT_DP = 50
|
||||
export const TABLET_BANNER_MIN_HEIGHT_DP = 90
|
||||
|
||||
export interface ResponsiveLayoutMetrics {
|
||||
windowWidth: number
|
||||
isLargeScreen: boolean
|
||||
contentMaxWidth: number
|
||||
wideContentMaxWidth: number
|
||||
formMaxWidth: number
|
||||
actionButtonMaxWidth: number
|
||||
gridColumns: 1 | 2
|
||||
bannerSlotMinHeight: number
|
||||
}
|
||||
|
||||
export function resolveResponsiveLayout(windowWidth: number): ResponsiveLayoutMetrics {
|
||||
const safeWidth = Number.isFinite(windowWidth) && windowWidth > 0 ? windowWidth : 390
|
||||
const isLargeScreen = safeWidth >= TABLET_BREAKPOINT_DP
|
||||
return {
|
||||
windowWidth: safeWidth,
|
||||
isLargeScreen,
|
||||
contentMaxWidth: CONTENT_MAX_WIDTH_DP,
|
||||
wideContentMaxWidth: WIDE_CONTENT_MAX_WIDTH_DP,
|
||||
formMaxWidth: FORM_MAX_WIDTH_DP,
|
||||
actionButtonMaxWidth: ACTION_BUTTON_MAX_WIDTH_DP,
|
||||
gridColumns: isLargeScreen ? 2 : 1,
|
||||
bannerSlotMinHeight: isLargeScreen ? TABLET_BANNER_MIN_HEIGHT_DP : PHONE_BANNER_MIN_HEIGHT_DP,
|
||||
}
|
||||
}
|
||||
|
||||
export function useResponsiveLayout(): ResponsiveLayoutMetrics {
|
||||
const { width } = useWindowDimensions()
|
||||
return resolveResponsiveLayout(width)
|
||||
}
|
||||
|
||||
export function useContentWidth(maxWidth: number = CONTENT_MAX_WIDTH_DP): number {
|
||||
const { width } = useWindowDimensions()
|
||||
const safeWidth = Number.isFinite(width) && width > 0 ? width : 390
|
||||
const safeMax = Number.isFinite(maxWidth) && maxWidth > 0 ? maxWidth : CONTENT_MAX_WIDTH_DP
|
||||
return Math.min(safeWidth, safeMax)
|
||||
}
|
||||
|
||||
export type ContentColumnVariant = 'default' | 'form' | 'wide'
|
||||
|
||||
export interface ContentColumnProps {
|
||||
variant?: ContentColumnVariant
|
||||
maxWidth?: number
|
||||
style?: StyleProp<ViewStyle>
|
||||
testID?: string
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export function resolveContentMaxWidth(
|
||||
variant: ContentColumnVariant = 'default',
|
||||
maxWidth?: number,
|
||||
): number {
|
||||
if (maxWidth !== undefined && Number.isFinite(maxWidth) && maxWidth > 0) {
|
||||
return maxWidth
|
||||
}
|
||||
if (variant === 'form') return FORM_MAX_WIDTH_DP
|
||||
if (variant === 'wide') return WIDE_CONTENT_MAX_WIDTH_DP
|
||||
return CONTENT_MAX_WIDTH_DP
|
||||
}
|
||||
|
||||
export function ContentColumn({
|
||||
variant = 'default',
|
||||
maxWidth,
|
||||
style,
|
||||
testID,
|
||||
children,
|
||||
}: ContentColumnProps): React.ReactElement {
|
||||
const resolvedMaxWidth = resolveContentMaxWidth(variant, maxWidth)
|
||||
|
||||
return (
|
||||
<View
|
||||
testID={testID}
|
||||
style={[styles.column, { maxWidth: resolvedMaxWidth }, style]}
|
||||
>
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
column: {
|
||||
width: '100%',
|
||||
alignSelf: 'center',
|
||||
},
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue