-
Notifications
You must be signed in to change notification settings - Fork 141
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
blurandgrayscaleworked 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, (they work, check below answers)sepia, invert, dropShadow are missing.
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
- Feedback regarding the approach in feat(iOS) - blur filter using SwiftUI facebook/react-native#52495.
- Any alternate approaches or improvements we can think of.
cc - @NickGerleman @joevilches