Skip to main content

Using Mapping

The useStyled hook connects a custom component to the Eva Design System style mapping. It resolves Eva styles based on the component's semantic properties and interaction state (focused, pressed, disabled, etc.) and returns them to the component.

warning

useStyled replaces the styled higher-order function, which was removed in UI Kitten 6.0.0. See the 5.x to 6.0.0 Migration guide.

Import​

import { useStyled } from '@ui-kitten/components';

Basic Usage​

import React from 'react';
import { TouchableOpacity } from 'react-native';
import { useStyled } from '@ui-kitten/components';

const MyComponent = ({ appearance, status, size, style, ...props }) => {
const { style: evaStyle } = useStyled('MyComponent', { appearance, status, size });

return (
<TouchableOpacity style={[evaStyle, style]} {...props} />
);
};

export default MyComponent;

The hook takes the component name as defined in your Eva mapping and the semantic properties to resolve it against. It returns the computed style, the current theme, and a dispatch function for interaction states.

Interaction States​

Call dispatch to tell Eva which interaction states are active. The style is recalculated for the states you pass.

import React from 'react';
import { TouchableOpacity } from 'react-native';
import { useStyled, Interaction } from '@ui-kitten/components';

const MyComponent = ({ appearance, style, ...props }) => {
const { style: evaStyle, dispatch } = useStyled('MyComponent', { appearance });

return (
<TouchableOpacity
{...props}
activeOpacity={1.0}
style={[evaStyle, style]}
onPressIn={() => dispatch([Interaction.ACTIVE])}
onPressOut={() => dispatch([])}
/>
);
};

export default MyComponent;

Interaction is an enum of HOVER, ACTIVE, FOCUSED, INDETERMINATE, and VISIBLE.

Parameters​

ParameterTypeDefaultDescription
componentNamestring-The component name as defined in the Eva mapping configuration.
optionsUseStyledOptions{}Semantic properties to resolve the mapping against.

UseStyledOptions​

PropertyTypeDescription
appearancestringAppearance defined in the component mapping.
statusstringStatus variant, e.g. primary, danger.
sizestringSize variant, e.g. small, large.
categorystringCategory variant, used by Text.
disabledbooleanWhether the disabled state mapping applies.
checkedbooleanWhether the checked state mapping applies.
selectedbooleanWhether the selected state mapping applies.
indeterminatebooleanWhether the indeterminate state mapping applies.
levelstringLevel variant, used by Layout.
shapestringShape variant, e.g. round, rounded.

Any other key is passed through to the mapping resolver, which is how the Calendar mapping consumes bounding, today, and range.

Return Value​

PropertyTypeDescription
styleStyleTypeThe resolved style object for the current properties and interactions.
themeThemeTypeThe current Eva theme variables.
dispatch(interactions: Interaction[]) => voidSets the active interaction states and recalculates the style.

Storybook​

Live examples coming soon via Storybook.