import React from 'react'; import type { StyleProp, SwitchProps, ViewStyle } from 'react-native'; import { StyleSheet, Switch } from 'react-native'; import { maybeGenerateStringFromElement } from '../internal/maybeGenerateStringFromElement'; import { FormField } from './FormField'; import { HideChildrenFromAccessibilityTree } from './HideChildrenFromAccessibilityTree'; import { SwitchWrapper } from './SwitchWrapper'; type SwitchListItemProps = React.PropsWithChildren< Omit & { labelComponent: JSX.Element; labelPosition?: 'left' | 'right'; style?: StyleProp; switchStyle?: StyleProp; value: boolean; onValueChange: () => void; } >; export const SwitchListItemBase = ({ children, testID, labelComponent, labelPosition = 'left', style = {}, switchStyle = {}, value, onValueChange, ...rest }: SwitchListItemProps) => { const isLabelPositionLeft = labelPosition === 'left'; const accessibilityLabel = React.useMemo( () => maybeGenerateStringFromElement(labelComponent, rest.accessibilityLabel), [labelComponent, rest.accessibilityLabel], ); return ( {isLabelPositionLeft ? labelComponent : null} {children ? ( children ) : ( )} {isLabelPositionLeft ? null : labelComponent} ); }; export const SwitchListItem = React.memo(SwitchListItemBase); const allStyles = StyleSheet.create({ container: { flexDirection: 'row', width: '100%', alignContent: 'center', alignItems: 'center', }, });