/* eslint-disable @typescript-eslint/no-unused-vars */ import React from 'react'; import Page from '../Page'; import useToolkit from '../toolkit/useToolkit'; import cssInheritanceConfig from './cards/cssInheritanceConfig'; import RefCssProcessor from '../components/RefCssProcessor'; import RefTRE from '../components/RefTRE'; import { RenderHTMLProps } from 'react-native-render-html'; const mixedStyleExample = `const mixedStyles = { whiteSpace: 'normal', color: 'gray' }`; const mixedStyleRenderCard: RenderHTMLProps = { source: { html: `

Hello world! A link!

` }, tagsStyles: { body: { whiteSpace: 'normal', color: 'gray' }, a: { color: 'green' } } }; export default function PageConceptCSS() { const { Acronym, Admonition, Bold, Header, Paragraph, Chapter, SourceDisplay, RefLibrary, RefRNSymbol, RefHtmlElement, RefCssProperty, RefRenderHtmlProp, RefHtmlAttr, RefDoc, RenderHtmlCard, RefCSSProcessor, RefRenderHTMLExport, Section, InlineCode, Hyperlink, List, ListItem, SvgFigure } = useToolkit(); return (
There are significant differences between the CSS standard and how styles are handled in React Native. Most notably,{' '} styles don't inherit from{' '} styles. The reconciliation is handled by the .
As stated before, a React Native cannot receive textAlign style. It could even crash the native app. The and libraries handle{' '} inheritable CSS properties {' '} by merging inheritable properties in the . Every CSS property has a validator registered in the CSS processor, in charge of validating values for those rules. Validators are multipurposed: Handle special units such as absolute (pt),{' '} relative (rem) and keywords such as{' '} small (font-size) and{' '} thin (for borders) and translate those values in DIP (device independent pixels). Group properties by inheritability, native target ( block for and{' '} text for ), and compatibility (native for properties translatable as native styles and web for other properties). Discard properties which values are invalid. Note that special inherit,{' '} initial and unset{' '} values are not supported. Mixed styles declarations ( ) are a blend between React Native styles (ViewStyle,{' '} TextStyles) and{' '} CSS properties {' '} such as those handled by the CSS processor. This format enables features that cannot be handled directly by React Native style engine. For example collapsing,{' '} , font selection (see{' '} page) or{' '} support in images (see{' '} page). Despite its lack of complex selectors,{' '} CSS specificity {' '} will be honoured by this library. Most notably, a CSS property will be resolved by applying the following precedence in ascending order (latest will override formers): Inherited styles User Agent styles (see ,{' '} element model) Tags styles ( prop) Classes styles ( prop) IDs styles ( prop) Inline styles ( DOM node attribute) So inline styles will take precedence over IDs styles, which will take precedence over classes styles, ...etc. important! directives, complex selectors such as div > *, pseudo-classes and pseudo-elements are not supported.
); }