CSS Processing
There are significant differences between the CSS standard and how styles are handled in React Native. Most notably, โText styles don't inherit from โView styles. The reconciliation is handled by the โTRE.
Inheritance#
As stated before, a React Native โView cannot receive textAlign style. It could even crash the native app. The โ@native-html/css-processor and โ@native-html/transient-render-engine libraries handle inheritable CSS properties by merging inheritable properties in the โTRT.
- JSX Source
- HTML Snippet
- TRT Snapshot
Translation#
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 assmall(font-size) andthin(for borders) and translate those values in DIP (device independent pixels).Group properties by inheritability, native target (block for โ
Viewand text for โText), and compatibility (native for properties translatable as native styles and web for other properties).Discard properties which values are invalid.
important
Note that special inherit, initial and unset values are not supported.
Mixed Styles Declaration#
Mixed styles declarations (โMixedStyleDeclaration) 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 โwhite-space collapsing, โlist-style-type, font selection (see โTextual page) or โobject-fit support in images (see โImages page).
Specificity#
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 โTransient Render Engine, element model)
Tags styles (โ
tagsStylesprop)Classes styles (โ
classesStylesprop)IDs styles (โ
idsStylesprop)Inline styles (โ
styleDOM node attribute)
So inline styles will take precedence over IDs styles, which will take precedence over classes styles, ...etc.
important
important! directives, complex selectors such as div > *, pseudo-classes and pseudo-elements are not supported.