Skip to main content

Class: EStyleSheetClass

Constructors​

new EStyleSheetClass()​

new EStyleSheetClass(): EStyleSheetClass

Constructor

Returns​

EStyleSheetClass

Defined in​

packages/core/src/api.ts:38

Properties​

absoluteFill​

absoluteFill: RegisteredStyle<AbsoluteFillStyle> = StyleSheet.absoluteFill

Defined in​

packages/core/src/api.ts:27


absoluteFillObject​

absoluteFillObject: AbsoluteFillStyle = StyleSheet.absoluteFillObject

Defined in​

packages/core/src/api.ts:26


child()​

child: <T>(styles, styleName, index, count) => AnyStyle

Returns styles with pseudo classes :first-child, :nth-child-even, :last-child according to index and count.

Type Parameters​

• T = StyleSet<any>

Parameters​

• styles: T

• styleName: string

• index: number

Index of item for style

• count: number

Total count of items

Returns​

AnyStyle

styles

Defined in​

packages/core/src/api.ts:29


compose()​

compose: <T, U, V>(style1, style2) => StyleProp<T> = StyleSheet.compose

Combines two styles such that style2 will override any styles in style1. If either style is falsy, the other one is returned without allocating an array, saving allocations and maintaining reference equality for PureComponent checks.

Type Parameters​

• T extends ImageStyle | TextStyle | ViewStyle

• U extends ImageStyle | TextStyle | ViewStyle

• V extends ImageStyle | TextStyle | ViewStyle

Parameters​

• style1: StyleProp<U> | StyleProp<U>[]

• style2: StyleProp<V> | StyleProp<V>[]

Returns​

StyleProp<T>

Defined in​

packages/core/src/api.ts:23


flatten()​

flatten: <T>(style?) => T extends infer U[] ? U : T = StyleSheet.flatten

Flattens an array of style objects, into one aggregated style object.

Example:

const styles = StyleSheet.create({
listItem: {
flex: 1,
fontSize: 16,
color: 'white'
},
selectedListItem: {
color: 'green'
}
});

StyleSheet.flatten([styles.listItem, styles.selectedListItem])
// returns { flex: 1, fontSize: 16, color: 'green' }

Type Parameters​

• T

Parameters​

• style?: StyleProp<T>

Returns​

T extends infer U[] ? U : T

Defined in​

packages/core/src/api.ts:22


hairlineWidth​

hairlineWidth: number = StyleSheet.hairlineWidth

Defined in​

packages/core/src/api.ts:25


setStyleAttributePreprocessor()​

setStyleAttributePreprocessor: (property, process) => void = StyleSheet.setStyleAttributePreprocessor

WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will not be reliably announced. The whole thing might be deleted, who knows? Use at your own risk.

Sets a function to use to pre-process a style property value. This is used internally to process color and transform values. You should not use this unless you really know what you are doing and have exhausted other options.

Parameters​

• property: string

• process

Returns​

void

Defined in​

packages/core/src/api.ts:24

Methods​

build()​

build<TGlobalVariablesObject>(globalVars?): void

Calculates all stylesheets.

Type Parameters​

• TGlobalVariablesObject

Parameters​

• globalVars?: TGlobalVariables<TGlobalVariablesObject>

Global variables for all stylesheets

Returns​

void

Defined in​

packages/core/src/api.ts:74


clearCache()​

clearCache(): void

Clears all cached styles.

Returns​

void

Defined in​

packages/core/src/api.ts:159


create()​

create<T>(source): TNamedStyles<T>

Creates extended stylesheet object that will be calculated after build.

Type Parameters​

• T

Parameters​

• source: TExtendedNamedStyles<T>

Source style

Returns​

TNamedStyles<T>

Extended stylesheet object

Defined in​

packages/core/src/api.ts:60


subscribe()​

subscribe(event, listener): void

Subscribe to event. Currently, only 'build' event is supported.

Parameters​

• event: string

• listener: TListener

Returns​

void

void

This method is useful when you want to pre-render some component on init. As extended style is calculated after call of EStyleSheet.build(), it is not available instantly after creation so you should wrap pre-render info listener to build event:

const styles = EStyleSheet.create({
button: {
width: '80%',
},
});

// this will NOT work as styles.button is not calculated yet
let Button = <View style={styles.button}></View>;

// but this will work
let Button;
EStyleSheet.subscribe('build', () => {
Button = <View style={styles.button}></View>;
});

Defined in​

packages/core/src/api.ts:133


unsubscribe()​

unsubscribe(event, listener): void

Unsubscribe from event. Currently, only 'build' event is supported.

Parameters​

• event: string

• listener: TListener

Returns​

void

Defined in​

packages/core/src/api.ts:147


value()​

value(expr, prop?): any

Calculates particular expression. For some values you need to pass prop (e.g. percent).

Parameters​

• expr: Readonly<TValueExpr>

Value

• prop?: string

Property for which value is calculated. For example, to calculate percent values the function should know is it 'width' or 'height' to use proper reference value.

Returns​

any

Calculated result

Please note that in most cases EStyleSheet.value() should be used inside function, not directly:

const styles = EStyleSheet.create({
button1: {
width: () => EStyleSheet.value('$contentWidth') + 10, // <-- Correct!
},
button2: {
width: EStyleSheet.value('$contentWidth') + 10, // <-- Incorrect. Because EStyleSheet.build() may occur later and $contentWidth will be undefined at this moment.
},
});

Defined in​

packages/core/src/api.ts:100