Command palette

@yasinsensoy/native

React Native · APIs and utilities

Appearance

The library's built-in effects.

14 exports

The library's built-in effects. Same names as the web effects, and they can be combined as an array (["tilt", "glow"]). All render identically on both platforms; animations run on the native driver.

On press:

  • scale: presses in slightly.
  • ripple: a wave spreading from the pressed point.
  • pulse: a ring expanding outward from the element and fading.
  • bounce: presses in with a spring and bounces back.

While pressed or active (touch screens have no "hover"; web's hover state is press-and-hold here):

  • lift: the element rises slightly and its shadow grows.
  • border: the border turns to the accent color.
  • beam: a light beam rotating around the border.
  • glow: a light following the finger; the surface glows under the finger.
  • tilt: the element tilts in 3D toward the corner under the finger (the pressed side sinks).
  • shine: a diagonal shine passes over the element.
  • none: no effect; turns off the UIProvider appearance default.

Colors come from the element's accent color (tone). With "reduce motion" moving effects do not play; when scrolling starts (the finger moves more than 10 pixels) the effect is released, so lists do not stutter.

type BuiltinEffect = "scale" | "ripple" | "pulse" | "bounce" | "lift" | "border" | "beam" | "glow" | "tilt" | "shine" | "none"

Effect name: one of the built-in effects (BuiltinEffect) or a custom effect added via UIProvider appearance.effects.

type EffectName = BuiltinEffect | (string & {})

Type of the effect prop: a single effect or effects that work together. If omitted, the component's UIProvider appearance.defaults setting is used, otherwise the component's own default. "none" turns all off.

type EffectProp = EffectName | readonly EffectName[]

Examples

<View variant="outline" effect="ripple" onPress={open}>…</View>
<Card effect={["tilt", "glow"]}>…</Card>

EffectState

interface

Current state of the effect; passed to custom effects' style and layers.

NameTypeDescription
pressedbooleanIs the finger pressed on the element.
activebooleanWas active given to the component.
onbooleanpressed || active: the state in which "hover" effects run.
accentstringAccent color (from tone; an rgba() string).
widthnumberElement width (pixels; 0 before the first measurement).
heightnumberElement height (pixels; 0 before the first measurement).
radiusnumberBorder radius (pixels).
reducedMotionbooleanIs the "reduce motion" preference on.
uiUIContextValueTheme values (useUI).

EffectPress

interface

Press info; passed to a custom effect's onPressIn.

NameTypeDescription
xnumberHorizontal position of the pressed point relative to the element (pixels).
ynumberVertical position of the pressed point relative to the element (pixels).
widthnumberElement width (pixels).
heightnumberElement height (pixels).

Custom effect definition. One or more of three ways are used together:

  • Style: style is added to the element's own style; given a function it changes with the state (EffectState) (e.g. a neon shadow while pressed).
  • Layer: layer is drawn below the content in a layer clipped to the element's corners that does not block touches. Use Animated for your own animation.
  • On press: onPressIn is called on every press (also with "reduce motion"; skip the animation yourself).
NameTypeDescription
style?StyleProp<ViewStyle> | ((state: EffectState) => StyleProp<ViewStyle>)Style to add to the element, or a function producing style from the state.
layer?ComponentType<EffectState>Component drawn in the clipped effect layer.
onPressIn?(press: EffectPress) => voidCalled on every press.

Examples

const effects = {
  neon: {
    style: ({ on, accent }) => on && { boxShadow: `0px 0px 24px 0px ${accent}` },
  },
  noise: { layer: ({ width, height }) => <Noise w={width} h={height} /> },
} satisfies Record<string, EffectDefinition>;

Info passed to a custom variant's style function.

NameTypeDescription
uiUIContextValueTheme values (useUI).
toneToneThe component's color.
accentstringAccent color (from tone; an rgba() string).

Style of the variant. Besides View style, color can be given: the text and icon color (for components with text like buttons, badges, alerts; the equivalent of web's text-* class).

type VariantViewStyle = ViewStyle & { /** Text and icon color of the content. */ color?: string; }

Extends: ViewStyle

NameTypeDescription
color?stringText and icon color of the content.

Variant style: a fixed style or a function producing style from the theme.

type VariantStyle = VariantViewStyle | ((context: VariantContext) => VariantViewStyle)

Custom variant definition. A style is used directly; an object can derive from a built-in variant and take separate styles per color (tone). If a built-in variant name is used (e.g. view: { outline: … }), the style is added on top of that variant.

type VariantEntry = VariantStyle | { /** Built-in variant to base on (e.g. `"outline"`). If omitted, only the base layout remains. */ extends?: string; /** Style added for every color. */ style?: VariantStyle; /** Style added per color (`tone`). */ tones?: Partial<Record<Tone, VariantStyle>>; }

Examples

variants: {
  view: {
    neon: ({ accent }) => ({ backgroundColor: "#000", borderWidth: 1, borderColor: accent }),
    frosted: { extends: "glass", style: { borderRadius: 24 } },
    brand: { extends: "soft", tones: { primary: { backgroundColor: "#ede9fe" } } },
  },
}

Keys of components that take custom variants (same names as web's VariantComponent).

  • view → View, card → Card.
  • button: Button, IconButton, ButtonGroup and everything that uses buttons (Dialog, Form buttons…).
  • field: all form fields (TextField, Textarea, Select, NumberInput, DatePicker…).
  • The others are the component of the same name (emptyState → EmptyState, otpInput → OtpInput).
type VariantComponent = "view" | "card" | "button" | "badge" | "alert" | "stat" | "kbd" | "tabs" | "emptyState" | "field" | "accordion" | "stepper" | "otpInput" | "fab" | "timeline" | "radio" | "countdown" | "tableOfContents"

Keys of components that take effects; AppearanceConfig.defaults uses these keys (same names as web's EffectComponent).

type EffectComponent = VariantComponent | "avatar" | "checkbox" | "switch" | "collapsible" | "sidebar" | "breadcrumb" | "menu" | "treeView" | "rating" | "colorSwatch" | "kanban" | "notificationCenter" | "fileUpload" | "image" | "gallery" | "dialog" | "sheet" | "popover" | "toast"

A component's default appearance settings.

NameTypeDescription
variant?stringDefault variant name: built-in or added via variants.
effect?EffectPropDefault effect or effects.
tone?ToneDefault color (if the component supports it).
size?SizeDefault size (if the component supports it).
shape?stringDefault corner shape (buttons only: rounded, pill, sharp).

The app's appearance settings: component defaults, custom effects and custom variants. Passed to the UIProvider appearance prop; same structure as web's UIProvider appearance (styles instead of classes).

Define the object outside components (a new object on every render defeats the cache).

NameTypeDescription
defaults?Partial<Record<EffectComponent, ComponentDefaults>>Default variant, effect, tone, size, shape per component. A prop given to the component always wins.
effects?Readonly<Record<string, EffectDefinition>>Custom effects: name → definition. See EffectDefinition.
variants?Partial<Record<VariantComponent, Readonly<Record<string, VariantEntry>>>>Custom variants per component: name → style. See VariantEntry.

Examples

const appearance: AppearanceConfig = {
  defaults: { view: { effect: "scale" }, card: { variant: "elevated", effect: ["lift", "glow"] } },
  effects: { neon: { style: ({ on, accent }) => on && { boxShadow: `0px 0px 20px 0px ${accent}` } } },
  variants: { view: { brand: { extends: "soft", style: { borderRadius: 20 } } } },
};
<UIProvider appearance={appearance}>…</UIProvider>