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.
#
InheritanceAs 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.
#
TranslationEvery 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 โ
View
and 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 DeclarationMixed 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).
#
SpecificityDespite 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 (โ
tagsStyles
prop)Classes styles (โ
classesStyles
prop)IDs styles (โ
idsStyles
prop)Inline styles (โ
style
DOM 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.