react-native 调用手机自带分享

发布时间 2023-07-19 10:29:43作者: 龙卷风吹毁停车场
实现效果 

import Share from 'react-native-share'
import ViewShot from 'react-native-view-shot'

const shotRef = useRef<ViewShot>(null)

const getTime = () => {
    return new Date().getTime().toString()
}

const OnShare = () => {
    shotRef.current!.capture().then(uri => {
      Share.open({
        url: uri
      })
    })
  }

<Button onPress={OnShare}>Share</Button>

<ViewShot
        style={styles.shotWrap}
        ref={shotRef}
        options={{
          fileName: getTime(),
          format: 'png',
          quality: 0.9
        }}>
         //内容可自定义
          <Image style={[styles.imgsShera]} resizeMode="cover" source={require('./assets/shera.png')}></Image>
      </ViewShot>