Filters, Blend Modes, Outlines and Gradients

+15 Mana ✨

Four groups of View style props cover effects you would otherwise bake into images: filter for brightness, blur and color changes, mixBlendMode for blending, the outline props for rings outside the border, and backgroundImage for gradients. Most of them run only on the New Architecture, and several work on Android alone, so the platform support decides what a cross-platform screen can rely on. On Android, filter also changes how a View's children are clipped.

Key terms

  • filter: a View style prop holding a list of filter functions that apply to the View and its descendants.
  • mixBlendMode: a style prop that controls how a View blends its colors with the other elements in its stacking context.
  • isolation: a style prop whose isolate value makes a view form a stacking context.
  • outlineWidth: the width of an outline drawn outside the border, which doesn't affect layout.
  • backgroundImage: a style prop that draws linear-gradient() and radial-gradient() with a web-like syntax.

Two filter functions work on iOS

filter is only available on the New Architecture, and it takes an array of single-key objects or a web-syntax string. Only brightness and opacity are available on iOS, which makes them the two you can use everywhere. Each takes a non-negative number or a percentage, where 50% equals 0.5.

The rest are Android only: blur, contrast, dropShadow, grayscale, hueRotate, invert, sepia and saturate, and blur and dropShadow also need Android 12 or later. blur takes a radius in dp and no percentages. grayscale, invert and sepia reach the full effect at 1 or 100%, and hueRotate takes an angle in deg or rad, where 360deg has no effect.

Filters clip children on Android

filter applies to the View's descendants as well as the View itself. The docs say it implies overflow: hidden, but only Android clips a filtered View's children: it clips the View's drawing to its padding box whenever a filter is set, even when its overflow is 'visible'. iOS clips only when overflow is set, so the same layout can clip on one platform and not on the other.

That matters for any child placed outside its parent's box, such as a status dot hanging off an avatar's corner. The MemberAvatar example dims a disabled member with filter: [{brightness: 0.6}] and keeps the dot whole by putting the filter on an inner View that wraps only the photo:

tsx
<View style={disabled ? styles.dimmed : undefined}>
  <Image source={{uri}} style={styles.photo} />
</View>
<View style={styles.dot} />

The dot is a sibling of the filtered View, so it is no longer one of its descendants and Android doesn't cut it off.

Blending with mixBlendMode and isolation

mixBlendMode is only available on the New Architecture and, on Android, from Android 10. Older Android versions ignore it. It accepts normal, multiply, screen, overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color, luminosity and plus-lighter. With normal the View is drawn over its background without blending, and with multiply its colors are multiplied by the colors under it.

A View blends with the other elements in its stacking context. isolation (New Architecture only) defaults to auto, which does nothing, and isolation: 'isolate' makes the view form a stacking context, so a blended child mixes only with what that view holds. A non-identity transform, a filter or a blend mode other than normal also makes a view form one.

Outlines that leave layout alone

An outline is drawn outside the border, and neither outlineWidth nor outlineOffset affects layout, so a selection ring can come and go without moving the grid around it:

tsx
selected: {outlineWidth: 2, outlineOffset: 3, outlineColor: '#2563eb', outlineStyle: 'dashed'},

All four outline props, outlineWidth, outlineColor, outlineOffset and outlineStyle, are New Architecture only. outlineStyle takes 'solid', 'dotted' or 'dashed', and outlineOffset sets the space between the outline and the element's bounds. The native defaults are a solid style with a zero width and offset, so nothing shows until you set outlineWidth.

Gradients with backgroundImage

backgroundImage takes a string such as 'linear-gradient(160deg, #0f172a, #1d4ed8)' or an array of gradient objects. The PromoBanner example uses an object, with type, an optional direction and colorStops. Each stop has a color and optional positions, and stops can use PlatformColor. Without a direction, a linear gradient runs at 180 degrees, top to bottom. A radial gradient defaults to an ellipse shape, the farthest-corner size and a centered position.

The banner also sets isolation: 'isolate' and gives a decorative circle mixBlendMode: 'screen', so the circle blends with the gradient inside the banner and with nothing behind it. When a gradient should cover only part of a View, backgroundSize, backgroundRepeat (repeat, space, round or no-repeat) and backgroundPosition control its size, tiling and placement.

Code Examples

tsx
import {Image, StyleSheet, View} from 'react-native';

type MemberAvatarProps = {uri: string; disabled: boolean; online: boolean};

export function MemberAvatar({uri, disabled, online}: MemberAvatarProps) {
  return (
    <View style={styles.avatar}>
      {/* The filter sits on an inner View that wraps only the photo */}
      <View style={disabled ? styles.dimmed : undefined}>
        <Image source={{uri}} style={styles.photo} />
      </View>
      {/* The dot is outside the filtered View, so it isn't clipped */}
      {online && <View style={styles.dot} />}
    </View>
  );
}

const styles = StyleSheet.create({
  avatar: {width: 48, height: 48},
  // brightness works on iOS and Android
  dimmed: {filter: [{brightness: 0.6}]},
  photo: {width: 48, height: 48, borderRadius: 24},
  dot: {
    position: 'absolute',
    top: -4,
    right: -4,
    width: 14,
    height: 14,
    borderRadius: 7,
    backgroundColor: '#16a34a',
  },
});
tsx
import {StyleSheet, Text, View} from 'react-native';

export function PromoBanner({headline}: {headline: string}) {
  return (
    <View style={styles.banner}>
      <View style={styles.glow} />
      <Text style={styles.headline}>{headline}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  banner: {
    padding: 24,
    borderRadius: 20,
    overflow: 'hidden',
    // The glow blends inside the banner only
    isolation: 'isolate',
    backgroundImage: [
      {
        type: 'linear-gradient',
        direction: '135deg',
        colorStops: [{color: '#7c3aed'}, {color: '#db2777'}],
      },
    ],
  },
  glow: {
    position: 'absolute',
    top: -40,
    right: -40,
    width: 160,
    height: 160,
    borderRadius: 80,
    backgroundColor: '#f59e0b',
    // Needs Android 10 or later on Android
    mixBlendMode: 'screen',
  },
  headline: {color: '#ffffff', fontSize: 22, fontWeight: '700'},
});
✓ Completed