2015-10-05 20:41:32 +00:00
|
|
|
/**
|
2016-11-08 23:40:04 +00:00
|
|
|
* Basic [Android] Example for react-native-blur
|
|
|
|
* https://github.com/react-native-community/react-native-blur
|
2015-10-05 20:41:32 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
2017-04-11 09:48:36 +00:00
|
|
|
import React, { Component } from 'react';
|
2016-11-08 23:40:04 +00:00
|
|
|
import {
|
2015-10-05 20:41:32 +00:00
|
|
|
AppRegistry,
|
2016-04-11 04:13:01 +00:00
|
|
|
Image,
|
|
|
|
findNodeHandle,
|
2015-10-05 20:41:32 +00:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
2017-04-11 09:48:36 +00:00
|
|
|
View,
|
2017-04-17 15:28:34 +00:00
|
|
|
Dimensions,
|
|
|
|
Switch,
|
|
|
|
InteractionManager,
|
2016-11-08 23:40:04 +00:00
|
|
|
} from 'react-native';
|
2017-04-17 15:28:34 +00:00
|
|
|
import AndroidSegmented from 'react-native-segmented-android';
|
2015-10-05 20:41:32 +00:00
|
|
|
|
2017-04-11 09:48:36 +00:00
|
|
|
import { BlurView } from 'react-native-blur';
|
2016-04-11 04:13:01 +00:00
|
|
|
|
2017-04-17 15:28:34 +00:00
|
|
|
const BLUR_TYPES = ['xlight', 'light', 'dark'];
|
|
|
|
|
2016-11-08 23:40:04 +00:00
|
|
|
class Basic extends Component {
|
|
|
|
constructor() {
|
2017-04-11 09:48:36 +00:00
|
|
|
super();
|
2016-11-08 23:40:04 +00:00
|
|
|
this.state = {
|
2017-04-17 15:28:34 +00:00
|
|
|
showBlur: true,
|
|
|
|
viewRef: null,
|
|
|
|
activeSegment: 2,
|
|
|
|
blurType: 'dark',
|
2017-04-11 09:48:36 +00:00
|
|
|
};
|
2016-04-11 04:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
imageLoaded() {
|
2017-04-17 15:28:34 +00:00
|
|
|
// Workaround for a tricky race condition on initial load.
|
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({ viewRef: findNodeHandle(this.refs.backgroundImage) });
|
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onChange(selected) {
|
|
|
|
this.setState({
|
|
|
|
activeSegment: selected,
|
|
|
|
blurType: BLUR_TYPES[selected],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBlurView() {
|
|
|
|
const tintColor = ['#ffffff', '#000000'];
|
2019-03-26 18:19:21 +00:00
|
|
|
if (this.state.blurType === 'xlight') {tintColor.reverse();}
|
2017-04-17 15:28:34 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
{this.state.viewRef && <BlurView
|
|
|
|
viewRef={this.state.viewRef}
|
|
|
|
style={styles.blurView}
|
|
|
|
|
|
|
|
blurRadius={9}
|
|
|
|
blurType={this.state.blurType}
|
|
|
|
|
|
|
|
// The following props are also available on Android:
|
|
|
|
|
|
|
|
// blurRadius={20}
|
|
|
|
// downsampleFactor={10}
|
|
|
|
// overlayColor={'rgba(0, 0, 255, .6)'} // set a blue overlay
|
|
|
|
/>}
|
|
|
|
|
|
|
|
<Text style={[styles.text, { color: tintColor[0] }]}>
|
|
|
|
Blur component (Android)
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<AndroidSegmented
|
|
|
|
tintColor={tintColor}
|
|
|
|
style={{
|
|
|
|
width: Dimensions.get('window').width,
|
|
|
|
height: 28,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
}}
|
|
|
|
childText={BLUR_TYPES}
|
2019-03-26 18:19:21 +00:00
|
|
|
orientation="horizontal"
|
2017-04-17 15:28:34 +00:00
|
|
|
selectedPosition={this.state.activeSegment}
|
|
|
|
onChange={this._onChange.bind(this)} />
|
|
|
|
|
|
|
|
</View>
|
2019-03-26 18:19:21 +00:00
|
|
|
);
|
2016-04-11 04:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2017-04-11 09:48:36 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
<Image
|
|
|
|
source={require('./bgimage.jpeg')}
|
|
|
|
style={styles.image}
|
|
|
|
ref={'backgroundImage'}
|
|
|
|
onLoadEnd={this.imageLoaded.bind(this)} />
|
|
|
|
|
2017-04-17 15:28:34 +00:00
|
|
|
{ this.state.showBlur ? this.renderBlurView() : null }
|
2017-04-11 09:48:36 +00:00
|
|
|
|
2017-04-17 15:28:34 +00:00
|
|
|
<View
|
|
|
|
style={styles.blurToggle}>
|
|
|
|
<Switch
|
|
|
|
onValueChange={(value) => this.setState({showBlur: value})}
|
|
|
|
value={this.state.showBlur} />
|
|
|
|
</View>
|
2017-04-11 09:48:36 +00:00
|
|
|
</View>
|
2016-04-11 04:13:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:40:04 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: 'transparent',
|
2017-04-11 09:48:36 +00:00
|
|
|
},
|
|
|
|
image: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
2016-11-08 23:40:04 +00:00
|
|
|
resizeMode: 'cover',
|
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
},
|
2017-04-11 09:48:36 +00:00
|
|
|
blurView: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
},
|
|
|
|
text: {
|
2016-11-08 23:40:04 +00:00
|
|
|
fontSize: 22,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
textAlign: 'center',
|
|
|
|
margin: 10,
|
|
|
|
color: '#FFFFFF',
|
|
|
|
},
|
2017-04-17 15:28:34 +00:00
|
|
|
blurToggle: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 30,
|
|
|
|
right: 10,
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
},
|
2016-11-08 23:40:04 +00:00
|
|
|
});
|
|
|
|
|
2015-10-05 20:41:32 +00:00
|
|
|
AppRegistry.registerComponent('Basic', () => Basic);
|