UNPKG

1.3 kBTypeScriptView Raw
1import PropTypes from 'prop-types';
2import * as React from 'react';
3import { View, ViewPropTypes, findNodeHandle } from 'react-native';
4import { NativeModulesProxy, requireNativeViewManager } from 'expo-core';
5
6type Props = {
7 tint: BlurTint;
8 intensity: number;
9} & React.ComponentProps<typeof View>;
10type BlurTint = 'light' | 'dark' | 'default';
11
12type ComponentOrHandle = null | number | React.Component<any, any> | React.ComponentClass<any>;
13
14export default class BlurView extends React.Component<Props> {
15 static propTypes = {
16 ...ViewPropTypes,
17 tint: PropTypes.oneOf(['light', 'default', 'dark'] as BlurTint[]).isRequired,
18 intensity: PropTypes.number.isRequired,
19 };
20
21 static defaultProps = {
22 tint: 'default' as BlurTint,
23 intensity: 50,
24 };
25
26 _root: ComponentOrHandle = null;
27
28 _setNativeRef = (ref: ComponentOrHandle) => {
29 this._root = ref;
30 };
31
32 setNativeProps = nativeProps => {
33 if (this._root) {
34 NativeModulesProxy.ExpoBlurViewManager.updateProps(nativeProps, findNodeHandle(this._root));
35 }
36 };
37
38 render() {
39 let { style, ...props } = this.props;
40 return <NativeBlurView {...props} ref={this._setNativeRef} style={[style, { backgroundColor: 'transparent' }]} />;
41 }
42}
43
44const NativeBlurView = requireNativeViewManager('ExpoBlurView');