react-native-blur icon indicating copy to clipboard operation
react-native-blur copied to clipboard

how to use the viewRef in Android

Open AnisDerbel opened this issue 10 years ago • 44 comments

In your Description you didn't put an example of how to include the viewRef with the rendered component that we want to blur!

AnisDerbel avatar Jun 21 '16 17:06 AnisDerbel

I implement the Example of the refView but I always get this error "com.fivehundredpx.android.blur.BluringView cannot be cast to android.view.ViewGroup"

AnisDerbel avatar Jun 21 '16 20:06 AnisDerbel

cc @cmcewen

Kureev avatar Jun 22 '16 13:06 Kureev

@AnisDerbel running the example in the examples folder gives you that error? Can you post the stacktrace?

cmcewen avatar Jun 23 '16 02:06 cmcewen

I have the same issue:


E/unknown:React: Exception in native call from JS
                                                             java.lang.ClassCastException: com.fivehundredpx.android.blur.BlurringView cannot be cast to android.view.ViewGroup
                                                                 at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:298)
                                                                 at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:175)
                                                                 at com.facebook.react.uimanager.UIViewOperationQueue$2.run(UIViewOperationQueue.java:766)
                                                                 at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:830)
                                                                 at com.facebook.react.uimanager.GuardedChoreographerFrameCallback.doFrame(GuardedChoreographerFrameCallback.java:32)
                                                                 at com.facebook.react.uimanager.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:125)
                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:798)
                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:603)
                                                                 at android.view.Choreographer.doFrame(Choreographer.java:571)
                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
                                                                 at android.os.Handler.handleCallback(Handler.java:815)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                 at android.os.Looper.loop(Looper.java:194)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5631)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

npomfret avatar Jun 25 '16 19:06 npomfret

I ran the example on android and nothing is blurred. However it doesn't crash.

npomfret avatar Jun 25 '16 19:06 npomfret

Yeah the same case here , nothing happens!

AnisDerbel avatar Jun 25 '16 19:06 AnisDerbel

I have the same problem, someone can tell me?

Miraclesomeday avatar Jun 27 '16 07:06 Miraclesomeday

expecting

cdmalcl avatar Jun 27 '16 08:06 cdmalcl

What devices/version are you running on? This is what I see from a fresh clone/npm install from the repo. screen shot 2016-06-27 at 10 03 14 am

cmcewen avatar Jun 27 '16 14:06 cmcewen

I'm running on a physical device running android 5.1. The demo doesn't crash with the ClassCastException error as reported above, but there's no blurring.

npomfret avatar Jun 28 '16 07:06 npomfret

I'm experiencing the same issue. Running on android 5.1 API 22 and nothing is blurred.

vugman avatar Jun 30 '16 08:06 vugman

I'm also using Device with Android 5.1 API 22 and nothing is blurred.

AnisDerbel avatar Jun 30 '16 08:06 AnisDerbel

Sorry, I forgot to add the new BlurViewPackage() in MainActivity. Now, It is working perfectly in Nexus 5! Thanks for your library.

Miraclesomeday avatar Jun 30 '16 09:06 Miraclesomeday

I've just noticed that in the examples the code for android is quite different to the iOS code.

The android code uses the viewRef, but the iOS one doesn't.

The instructions don't mention this - is this difference required?

npomfret avatar Jun 30 '16 09:06 npomfret

Same issue here - not seeing blur on Genymotion Nexus 5 6.0.0. In my own app, I get the casting error.

jsierles avatar Jul 05 '16 08:07 jsierles

I think the casting error might come from the different in the android code to the iOS code, maybe? the instructions on the README are iOS specific, but that's not mentioned. If you look at the android example its quite different. I ran the demo and it didn't crash, but even then, it doesn't blur anything at all.

It would be great if someone could figure out a nice way to abstract away the differences... and to get it to blur on android!

npomfret avatar Jul 05 '16 13:07 npomfret

@npomfret change the demo as blow, see if blurred? imageLoaded() { let h = findNodeHandle(this.refs.backgroundImage); console.log(h); setTimeout( ()=>this.setState({viewRef: h}), 500 ) }

chenxiaohu avatar Jul 08 '16 09:07 chenxiaohu

@cmcewen Im running on Android 5.0 Asus Zenfone 2. If i use

<BlurView
          blurRadius={10}
          downsampleFactor={5}
          overlayColor={'rgba(255, 255, 255, 0.1)'}
          style={styles.blurView}
          viewRef={this.state.viewRef}
        />

I don't see the error but nothing gets blurred. And When I use

<BlurView blurType="light" style={styles.blur}>
          <Text>Hi, I am a tiny menu item</Text>
        </BlurView>

I see the ClassCastException. So what going on ?

Almjz avatar Jul 14 '16 07:07 Almjz

Ok, the demo also fails an Android if you put something inside the blur view (as @cmcewen said):

        <BlurView
          blurRadius={10}
          downsampleFactor={5}
          overlayColor={'rgba(255, 255, 255, 0.1)'}
          style={styles.blurView}
          viewRef={this.state.viewRef}
        >
          <Text style={styles.welcome}>Blur component</Text>
        </BlurView>

Also, I notice the style blurView is missing from the demo. But not matter what I've tried I can't make it blur anything.

npomfret avatar Jul 22 '16 15:07 npomfret

@cmcewen what virtual device is that screen shot from?

npomfret avatar Jul 24 '16 09:07 npomfret