暫無描述

Offscreen.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //@flow
  2. import React, { useState, useCallback } from 'react';
  3. import { SafeAreaView, Image, View } from 'react-native';
  4. import ViewShot from 'react-native-view-shot';
  5. import SvgUri from 'react-native-svg-uri';
  6. import Desc from './Desc';
  7. const OffscreenViewShot = ({ width, height, ...rest }) => (
  8. <ViewShot {...rest} style={{ width, height, position: 'absolute', right: -width - 5 }} />
  9. );
  10. const OffscreenExample = () => {
  11. const [source, setSource] = useState(null);
  12. const onCapture = useCallback(uri => setSource({ uri }), []);
  13. const width = 300;
  14. const height = 300;
  15. return (
  16. <SafeAreaView>
  17. <Desc desc="We have rendered this SVG as image offscreen:" />
  18. <Image fadeDuration={0} source={source} style={{ width, height }} />
  19. <OffscreenViewShot
  20. captureMode="continuous"
  21. onCapture={onCapture}
  22. width={width}
  23. height={height}
  24. >
  25. <SvgUri width={200} height={200} source={require('./homer-simpson.svg')} />
  26. </OffscreenViewShot>
  27. </SafeAreaView>
  28. );
  29. };
  30. OffscreenExample.navigationOptions = {
  31. title: 'Offscreen',
  32. };
  33. export default OffscreenExample;