No Description

Blur.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //@flow
  2. import React, { useState, useCallback, useRef, useEffect } from 'react';
  3. import { SafeAreaView, View, Image, findNodeHandle } from 'react-native';
  4. import { BlurView } from '@react-native-community/blur';
  5. import ViewShot from 'react-native-view-shot';
  6. import Desc from './Desc';
  7. const dimension = { width: 300, height: 300 };
  8. const BlurExample = () => {
  9. const [source, setSource] = useState(null);
  10. const [viewHandle, setRefHandle] = useState(null);
  11. const onCapture = useCallback(uri => setSource({ uri }), []);
  12. const viewRef = useRef();
  13. const ref = useRef();
  14. useEffect(() => {
  15. const timeout = setTimeout(() => {
  16. if (ref.current) ref.current.capture();
  17. }, 1000);
  18. return () => clearTimeout(timeout);
  19. }, []);
  20. const absoluteDimension = { ...dimension, position: 'absolute' };
  21. return (
  22. <SafeAreaView>
  23. <ViewShot ref={ref} captureMode="mount" onCapture={onCapture} style={dimension}>
  24. <Image
  25. source={require('./bg.jpg')}
  26. style={absoluteDimension}
  27. ref={ref => setRefHandle(findNodeHandle(ref))}
  28. />
  29. <BlurView blurType="light" blurAmount={10} style={absoluteDimension} viewRef={viewHandle} />
  30. </ViewShot>
  31. <Desc desc="above is a blurred image and below is a screenshot of it" />
  32. <Image fadeDuration={0} source={source} style={dimension} />
  33. </SafeAreaView>
  34. );
  35. };
  36. BlurExample.navigationOptions = {
  37. title: 'react-native-community/blur',
  38. };
  39. export default BlurExample;