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

viewRef is null

Open Kariko opened this issue 6 years ago • 20 comments

I want to blur on a View component, what should i do to make the View blur at the beginning? And what function i should use to replace the 'onLoadEnd' in the example?

RN:0.46.0 react-native-blur:3.1.3

Kariko avatar Aug 24 '17 09:08 Kariko

I have encountered this problem, and I can't solve it.

luck-cheng avatar Sep 07 '17 09:09 luck-cheng

Same issue... Works fine on iOS, fails on Android

jeffmwells avatar Sep 07 '17 18:09 jeffmwells

Me too . Not working on android.

Akaqlonist avatar Sep 11 '17 21:09 Akaqlonist

+1

ww930912 avatar Sep 20 '17 12:09 ww930912

+1

alexeymolchan avatar Sep 21 '17 12:09 alexeymolchan

+1

koansang avatar Sep 22 '17 05:09 koansang

Not working on Android as well.

batmanhit avatar Oct 06 '17 09:10 batmanhit

+1

niocncn avatar Oct 06 '17 12:10 niocncn

not working on Android when trying to blur a View: for me viewRef returns a number, but fails to findView

`@ReactProp(name = "viewRef") public void setViewRef(BlurringView view, int viewRef) { View viewToBlur = context.getCurrentActivity().findViewById(viewRef);

    if (viewToBlur != null) {
        view.setBlurredView(viewToBlur);
    }
}`

-- viewToBlur is null, for a single image its ok.

DanGDroid avatar Oct 25 '17 08:10 DanGDroid

Same issue here on Android on a View. Anyone got a solution?

robertftw avatar Oct 30 '17 13:10 robertftw

i got it to work, try wrapping all the view you want to blur in a single View.

render(){
    const {...} = this.props
    return (
<View style={styles.container}>
        <View style ={styles.container}
                   ref={(blurView) => {this.blurBackgroundView = blurView}}>
          {this.renderTitleSubtitle(currentStage, products)}
          {this.renderCurrentStage(currentStage)}
          {this.renderButtons(nextStage, currentStage)}
          {this.renderModal(saveCurrentDetails)}
        </View>
        {this.renderBlur()}
        {this.renderFinishModal(userName, lastStage)}
      </View>
)}

and pass the ref in :

componentDidMount () {
  this.setState({ blurViewRef: findNodeHandle(this.blurBackgroundView) });
}

the blur view:

renderBlur(){
    if(this.state.finishModalVisible){
      return   <BlurView
                  style={styles.absolute}
                  viewRef={this.state.blurViewRef}
                  blurType="dark"
                  blurAmount={10}
                />
    }else {
      return null;
    }
  }

Good luck!

DanGDroid avatar Oct 30 '17 14:10 DanGDroid

@DanGDroid On Android? Can't get it to work with the same layout:

componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.setState({ viewRef: findNodeHandle(this.view) });
    });
  }

  render() {
    const { isLoading } = this.props;
    if (!isLoading) {
      //   return null;
    }
    return (
      <View style={[styles.container, styles.absolute]}>
        <View style={styles.innerContainer} ref={ref => (this.view = ref)} />
        <View style={[styles.absolute, styles.center]}>
          <BlurView
            style={styles.absolute}
            viewRef={this.state.viewRef}
            blurType="light"
            blurAmount={4}
          />
          <ActivityIndicator size="large" color={Colors.flaktMiddleGrey} />
        </View>
      </View>
    );
  }
}

robertftw avatar Oct 31 '17 08:10 robertftw

this view you want to blur seems empty!?

<View style={styles.innerContainer} ref={ref => (this.view = ref)} />

DanGDroid avatar Oct 31 '17 15:10 DanGDroid

@DanGDroid Is has a background color and blurs it on iOS. Even if I add a text to it the text doesn't get blured.

robertftw avatar Nov 01 '17 08:11 robertftw

+1 only android

herarya avatar Jan 31 '18 01:01 herarya

+1

ThunderBoltEngineer avatar Mar 11 '18 10:03 ThunderBoltEngineer

Thanks @DanGDroid, your example works perfectly on both platforms.

lynnsouz avatar Apr 13 '18 14:04 lynnsouz

How to Blur a drawer component background View?

ajaykumar97 avatar Jun 05 '18 12:06 ajaykumar97

plz help me

GuoAxiang avatar Jun 19 '18 10:06 GuoAxiang

I regret trying to make this component work. What a mess.

wmonecke avatar Mar 18 '20 10:03 wmonecke