React Native: detect if UIVisualEffectView is supported

329 Views Asked by At

I'd like to use react-native-blur on my iOS app with React Native, using an alternative visualization on iOS 7 (such as a backgroundColor), which does not support UIVisualEffectView.

E.g.:

styles = { 
    backgroundColor: isVisualEffectViewSupported ? "transparent" : "rgba(0,0,0,.5)"
}

How can I detect if UIVisualEffectView is supported by the current platform?

2

There are 2 best solutions below

1
On

Objective-C:

Class cls = NSClassFromString(@"UIVisualEffectView");
if (cls) {
    // class exists, do whatever you need with it
} else {
    // class doesn't exists, fallback
}

Swift:

if NSClassFromString("UIVisualEffectView") != nil {
    println("UIVisualEffectView exists")
} else {
    println("UIVisualEffectView does not exists")
}
0
On

Just write a native module which export iOS version to JS, then JS detect the version and decide if UIVisualEffectView is supported.