La pregunta es bastante simple, tengo un texto, que tiene un accesorio predeterminado, fontSize , el problema es que quiero tener accesorios para cambiar ese tamaño cuando sea necesario, así que configuré la fuente predeterminada y accesorios para cambiar la fuente, pero realmente no lo hago. No sé cuál es la forma correcta de hacer esto.
Aquí está mi solución que no funcionó:
Los accesorios llamados textStyle , los defino usando la interfaz mecanografiada textStyle: TextStyle
Traté de tener condiciones en style como
style={textListStyle?.fontSize ?? 15} <== not workEl cumplidor se queja
No overload matches this call. Overload 1 of 2, '(props: TextProps | Readonly<TextProps>): Text', gave the following error. Type 'number' is not assignable to type 'StyleProp<TextStyle>'. Overload 2 of 2, '(props: TextProps, context: any): Text', gave the followingerror.
y lo intenté
style={!textListStyle?.fontSize ? 15 : textListStyle?.fontSize}Mismo problema, ¿cuál es la mejor solución? Muchas gracias
No estoy seguro de entender realmente lo que está tratando de hacer. Por lo que entendí, tienes un accesorio e intentas definir un tamaño de fuente determinado cuando el accesorio es verdadero y otro cuando no lo es.
Yo lo haría :
style={{fontSize: textListStyle.fontSize ? 15 : 20 }}O si su "textListStyle?.fontSize" es un número entero:
style={{fontSize: textListStyle?.fontSize ?? 15}}