最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

在很多App中都會(huì)涉及到分享,React Native提供了Modal組件用來(lái)實(shí)現(xiàn)一些模態(tài)彈窗,例如加載進(jìn)度框,分享彈框等。使用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
  },
});

當(dāng)點(diǎn)擊某個(gè)按鈕之后,就會(huì)彈出框,示例代碼如下:

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


//省略

onSharePress() {
    this.setState({showSharePop: !this.state.showSharePop})
  }
//增加點(diǎn)擊
<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}/>

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

相關(guān)文章

  • React?中使用?Redux?的?4?種寫(xiě)法小結(jié)

    React?中使用?Redux?的?4?種寫(xiě)法小結(jié)

    這篇文章主要介紹了在?React?中使用?Redux?的?4?種寫(xiě)法,Redux 一般來(lái)說(shuō)并不是必須的,只有在項(xiàng)目比較復(fù)雜的時(shí)候,比如多個(gè)分散在不同地方的組件使用同一個(gè)狀態(tài),本文就React使用?Redux的相關(guān)知識(shí)給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2022-06-06
  • React-Native使用Mobx實(shí)現(xiàn)購(gòu)物車(chē)功能

    React-Native使用Mobx實(shí)現(xiàn)購(gòu)物車(chē)功能

    本篇文章主要介紹了React-Native使用Mobx實(shí)現(xiàn)購(gòu)物車(chē)功能,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • Shopee在React?Native?架構(gòu)方面的探索及發(fā)展歷程

    Shopee在React?Native?架構(gòu)方面的探索及發(fā)展歷程

    這篇文章主要介紹了Shopee在React?Native?架構(gòu)方面的探索,本文會(huì)從發(fā)展歷史、架構(gòu)模型、系統(tǒng)設(shè)計(jì)、遷移方案四個(gè)方向逐一介紹我們?nèi)绾我徊讲降貪M足多團(tuán)隊(duì)在復(fù)雜業(yè)務(wù)中的開(kāi)發(fā)需求,需要的朋友可以參考下
    2022-07-07
  • react-redux多個(gè)組件數(shù)據(jù)共享的方法

    react-redux多個(gè)組件數(shù)據(jù)共享的方法

    這篇文章主要介紹了react-redux多個(gè)組件數(shù)據(jù)共享的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • react組件實(shí)例屬性state詳解

    react組件實(shí)例屬性state詳解

    這篇文章主要介紹了react組件實(shí)例屬性state,有狀態(tài)state的組件稱(chēng)作復(fù)雜組件,沒(méi)有狀態(tài)的組件稱(chēng)為簡(jiǎn)單組件,狀態(tài)里存儲(chǔ)數(shù)據(jù),數(shù)據(jù)的改變驅(qū)動(dòng)頁(yè)面的展示,本文結(jié)合實(shí)例代碼給大家詳細(xì)講解,需要的朋友可以參考下
    2023-02-02
  • React?18中的state概念與使用、注意問(wèn)題解決

    React?18中的state概念與使用、注意問(wèn)題解決

    state和props類(lèi)似,都是一種存儲(chǔ)屬性的方式,但是不同點(diǎn)在于state只屬于當(dāng)前組件,其他組件無(wú)法訪問(wèn),這篇文章主要介紹了React?18中的state概念與使用、注意問(wèn)題,需要的朋友可以參考下
    2022-12-12
  • React團(tuán)隊(duì)測(cè)試并發(fā)特性詳解

    React團(tuán)隊(duì)測(cè)試并發(fā)特性詳解

    這篇文章主要為大家介紹了React團(tuán)隊(duì)測(cè)試并發(fā)特性詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • react 原生實(shí)現(xiàn)頭像滾動(dòng)播放的示例

    react 原生實(shí)現(xiàn)頭像滾動(dòng)播放的示例

    這篇文章主要介紹了react 原生實(shí)現(xiàn)頭像滾動(dòng)播放的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • 詳解React如何使用??useReducer???高階鉤子來(lái)管理狀態(tài)

    詳解React如何使用??useReducer???高階鉤子來(lái)管理狀態(tài)

    useReducer是React中的一個(gè)鉤子,用于替代?useState來(lái)管理復(fù)雜的狀態(tài)邏輯,本文將詳細(xì)介紹如何在React中使用?useReducer高階鉤子來(lái)管理狀態(tài),感興趣的可以了解下
    2025-02-02
  • 關(guān)于hooks中useEffect()的使用總結(jié)

    關(guān)于hooks中useEffect()的使用總結(jié)

    這篇文章主要介紹了關(guān)于hooks中useEffect()的使用總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01

最新評(píng)論

平罗县| 察雅县| 凤台县| 泰州市| 连平县| 安新县| 行唐县| 富阳市| 高州市| 日土县| 嵩明县| 青河县| 伊金霍洛旗| 上犹县| 北碚区| 惠水县| 德兴市| 临沭县| 民丰县| 玉树县| 东宁县| 广元市| 双桥区| 寿阳县| 靖州| 大厂| 彩票| 新平| 济阳县| 五家渠市| 蒲江县| 卢氏县| 招远市| 新平| 和龙市| 广宁县| 绿春县| 黄梅县| 大连市| 栾川县| 电白县|