欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

React Native使用Modal自定義分享界面的示例代碼

 更新時間:2017年10月31日 16:26:16   作者:code_xzh  
本篇文章主要介紹了React Native使用Modal自定義分享界面的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

在很多App中都會涉及到分享,React Native提供了Modal組件用來實現(xiàn)一些模態(tài)彈窗,例如加載進度框,分享彈框等。使用Modal搭建分析的效果如下:

自定義的分析界面代碼如下:

ShareAlertDialog.js

/**
 * https://github.com/facebook/react-native
 * @flow 分享彈窗
 */


import React, {Component} from 'react';
import {View, TouchableOpacity, Alert,StyleSheet, Dimensions, Modal, Text, Image} from 'react-native';
import Separator from "./Separator";

const {width, height} = Dimensions.get('window');
const dialogH = 110;

export default class ShareAlertDialog extends Component {

  constructor(props) {
    super(props);
    this.state = {
      isVisible: this.props.show,
    };
  }

  componentWillReceiveProps(nextProps) {
    this.setState({isVisible: nextProps.show});
  }

  closeModal() {
    this.setState({
      isVisible: false
    });
    this.props.closeModal(false);
  }

  renderDialog() {
    return (
      <View style={styles.modalStyle}>
        <Text style={styles.text}>選擇分享方式</Text>
        <Separator/>
        <View style={{flex: 1, flexDirection: 'row', marginTop: 15}}>
          <TouchableOpacity style={styles.item} onPress={() => Alert.alert('分享到微信朋友圈')}>
            <Image resizeMode='contain' style={styles.image}
                source={require('../images/share_ic_friends.png')}/>
            <Text>微信朋友圈</Text>
          </TouchableOpacity>
          <TouchableOpacity style={styles.item}>
            <Image resizeMode='contain' style={styles.image}
                source={require('../images/share_ic_weixin.png')}/>
            <Text>微信好友</Text>
          </TouchableOpacity>
          <TouchableOpacity style={styles.item}>
            <Image resizeMode='contain' style={styles.image}
                source={require('../images/share_ic_weibo.png')}/>
            <Text>新浪微博</Text>
          </TouchableOpacity>
        </View>
      </View>
    )
  }

  render() {

    return (
      <View style={{flex: 1}}>
        <Modal
          transparent={true}
          visible={this.state.isVisible}
          animationType={'fade'}
          onRequestClose={() => this.closeModal()}>
          <TouchableOpacity style={styles.container} activeOpacity={1}
                   onPress={() => this.closeModal()}>
            {this.renderDialog()}
          </TouchableOpacity>
        </Modal>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'rgba(0, 0, 0, 0.5)',
  },
  modalStyle: {
    position: "absolute",
    top: height - 170,
    left: 0,
    width: width,
    height: dialogH,
    backgroundColor: '#ffffff'
  },
  subView: {
    width: width,
    height: dialogH,
    backgroundColor: '#ffffff'
  },
  text: {
    flex: 1,
    fontSize: 18,
    margin: 10,
    justifyContent: 'center',
    alignItems: 'center',
    alignSelf: 'center'
  },
  item: {
    width: width / 3,
    height: 100,
    alignItems: 'center',
    backgroundColor: '#ffffff'
  },
  image: {
    width: 60,
    height: 60,
    marginBottom: 8
  },
});

當點擊某個按鈕之后,就會彈出框,示例代碼如下:

constructor(props) {
    super(props);
    this.state = {
      showSharePop: false,//分享彈窗,默認不顯示
    }
  }


//省略

onSharePress() {
    this.setState({showSharePop: !this.state.showSharePop})
  }
//增加點擊
<NavigationBar
          navigator={this.props.navigator}
          popEnabled={false}
          style={{backgroundColor: "transparent", position: "absolute", top: 0, width}}
          leftButton={ViewUtils.getLeftButton(() => this.props.navigator.pop())}
          rightButton={ViewUtils.getShareButton(() => this.onSharePress())}/>

//添加ShareAlertDialog自定義組件
<ShareAlertDialog show={this.state.showSharePop} closeModal={(show) => {
          this.setState({showSharePop: show})
        }} {...this.props}/>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解析react?函數(shù)組件輸入卡頓問題?usecallback?react.memo

    解析react?函數(shù)組件輸入卡頓問題?usecallback?react.memo

    useMemo是一個react hook,我們可以使用它在組件中包裝函數(shù)??梢允褂盟鼇泶_保該函數(shù)中的值僅在依賴項之一發(fā)生變化時才重新計算,這篇文章主要介紹了react?函數(shù)組件輸入卡頓問題?usecallback?react.memo,需要的朋友可以參考下
    2022-07-07
  • React創(chuàng)建組件的三種方式及其區(qū)別

    React創(chuàng)建組件的三種方式及其區(qū)別

    本文主要介紹了React創(chuàng)建組件的三種方式及其區(qū)別,具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • react使用節(jié)流函數(shù)防止重復(fù)點擊問題

    react使用節(jié)流函數(shù)防止重復(fù)點擊問題

    這篇文章主要介紹了react使用節(jié)流函數(shù)防止重復(fù)點擊問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 基于react后端渲染模板引擎noox發(fā)布使用

    基于react后端渲染模板引擎noox發(fā)布使用

    本篇文章主要介紹了基于react后端渲染模板引擎noox發(fā)布使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • 教你如何從 html 實現(xiàn)一個 react

    教你如何從 html 實現(xiàn)一個 react

    react是一個簡單的javascript UI庫,用于構(gòu)建高效、快速的用戶界面。它是一個輕量級庫,因此很受歡迎。接下來通過本文給大家分享從 html 實現(xiàn)一個 react的方法,一起看看吧
    2021-07-07
  • React從react-router路由上做登陸驗證控制的方法

    React從react-router路由上做登陸驗證控制的方法

    本篇文章主要介紹了React從react-router路由上做登陸驗證控制的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • React 使用recharts實現(xiàn)散點地圖的示例代碼

    React 使用recharts實現(xiàn)散點地圖的示例代碼

    這篇文章主要介紹了React 使用recharts實現(xiàn)散點地圖的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • react 移動端實現(xiàn)列表左滑刪除的示例代碼

    react 移動端實現(xiàn)列表左滑刪除的示例代碼

    這篇文章主要介紹了react 移動端實現(xiàn)列表左滑刪除的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2019-07-07
  • 詳解如何在react中搭建d3力導(dǎo)向圖

    詳解如何在react中搭建d3力導(dǎo)向圖

    本篇文章主要介紹了如何在react中搭建d3力導(dǎo)向圖,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • create-react-app項目配置全解析

    create-react-app項目配置全解析

    這篇文章主要為大家介紹了create-react-app項目配置全解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06

最新評論