Skip to content

Implementing missing CSS filters on iOS #927

@intergalacticspacehighway

Description

Introduction

React Native added support for CSS like filter property. It currently supports blur, contrast, dropShadow, grayscale, hueRotate, invert, sepia, saturate, brightness and opacity on Android. On iOS, it currently supports brightness and opacity.

Details

If we want to add additional filter support on iOS, there are two approaches that we can take.

1. CAFilter private API

Upsides

Easy to implement - facebook/react-native#52028

Downsides

  • It is a private API. Although some frameworks are using it, there is always a risk of a breaking change or app rejection with a private API. Not worth adding to core imo. Someone can refer to this PR and build a library if needed.
  • Since it is a private API, documentation is lacking, hard to guess which filter is supported. In my testing blur and grayscale worked fine. It might be supporting all the filters since iOS uses it under the hood for many public APIs, but hard to guess the API.

2. SwiftUI modifiers

SwiftUI has a public API for many filters. blur, grayscale, brightness, saturation, hueRotation, contrast, opacity are available. However, sepia, invert, dropShadow are missing. (they work, check below answers)

Upsides

  • Public API, better documentation, no risk of rejection or breaking changes.
  • Supports all the filters. We can have feature parity with android.

Downsides

Implementation is a bit complicated facebook/react-native#52495. Would be helpful to get more feedback on this PR. There are some high level ideas to make it simple, would be awesome to get more thoughts on that as well.


Besides these two, other approach that was investigated is CIFilter. It works on Images. It is not feasible for dynamic views.

Discussion points

cc - @NickGerleman @joevilches

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions