暫無描述

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable react-native/no-inline-styles */
  2. //@flow
  3. import React, { useState, useCallback } from 'react';
  4. import { SafeAreaView, Image, View } from 'react-native';
  5. import ViewShot from 'react-native-view-shot';
  6. import RNFS from 'react-native-fs';
  7. import Desc from './Desc';
  8. const dimension = { width: 50, height: 50 };
  9. const FSExample = () => {
  10. const [source, setSource] = useState(null);
  11. const onCapture = useCallback(async file => {
  12. const data = await RNFS.readFile(file, 'base64');
  13. setSource({ uri: 'data:image/png;base64,' + data });
  14. }, []);
  15. return (
  16. <SafeAreaView>
  17. <ViewShot onCapture={onCapture} captureMode="mount" style={dimension}>
  18. <View
  19. style={{
  20. ...dimension,
  21. backgroundColor: 'red',
  22. }}
  23. />
  24. </ViewShot>
  25. <Desc desc="FS to get the image from captured file" />
  26. <Image fadeDuration={0} source={source} style={dimension} />
  27. </SafeAreaView>
  28. );
  29. };
  30. FSExample.navigationOptions = {
  31. title: 'react-native-fs',
  32. };
  33. export default FSExample;