React Native之Modal元件實現遮罩層效果
React-Native中Modal的使用
/**
* React Native App
* dongtao 2017/04/22
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Modal,
PixelRatio,
View
} from 'react-native';
class ModalDemo extends Component {
constructor(props) {
super(props);//這一句不能省略,照抄即可
this.state = {
animationType: 'none',//none slide fade
modalVisible: false,//模態場景是否可見
transparent: true,//是否透明顯示
};
}
render() {
let modalBackgroundStyle = {
backgroundColor: this.state.transparent ? 'rgba(0, 0, 0, 0.5)' : 'red',
};
let innerContainerTransparentStyle = this .state.transparent
? { backgroundColor: '#fff', padding: 20 }
: null;
return (
<View style={{ alignItems: 'center', flex: 1 }}>
<Modal
animationType={this.state.animationType}
transparent={this.state.transparent}
visible={this.state.modalVisible}
onRequestClose={() => { this._setModalVisible(false) } }
onShow={this.startShow}
>
<View style={[styles.container, modalBackgroundStyle]}>
<View style={[styles.innerContainer, innerContainerTransparentStyle]}>
<Text style={styles.date}>2016-08-11</Text>
<View style={styles.row}>
<View >
<Text style={styles.station}>長沙站</Text>
<Text style={styles.mp10}>8: 00出發</Text>
</View>
<View>
<View style={styles.at}></View>
<Text style={[styles.mp10, { textAlign: 'center' }]}>G888</Text>
</View>
<View >
<Text style={[styles.station, { textAlign: 'right' }]}>北京站</Text>
<Text style={[styles.mp10, { textAlign: 'right' }]}>18: 00抵達</Text>
</View>
</View>
<View style={styles.mp10}>
<Text>票價:¥600.00元</Text>
<Text>乘車人:東方耀</Text>
<Text>長沙站 火車南站 網售</Text>
</View>
<View style={[styles.mp10, styles.btn, { alignItems: 'center' }]}>
<Text style={styles.btn_text}>去支付</Text>
</View>
<Text
onPress={this._setModalVisible.bind(this,false) }
style={{fontSize:20,marginTop:10}}>
關閉
</Text>
</View>
</View>
</Modal>
<Text style={{ fontSize: 30,color:'red' }} onPress={this._setModalVisible.bind(this, true) }>預定火車票</Text>
</View>
);
}
_setModalVisible = (visible) => {
this.setState({ modalVisible: visible });
}
startShow=()=>{
alert('開始顯示了');
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 40,
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
},
row: {
alignItems: 'center',
flex: 1,
flexDirection: 'row',
marginBottom: 20,
},
rowTitle: {
flex: 1,
fontWeight: 'bold',
},
button: {
borderRadius: 5,
flex: 1,
height: 44,
alignSelf: 'stretch',
justifyContent: 'center',
overflow: 'hidden',
},
buttonText: {
fontSize: 18,
margin: 5,
textAlign: 'center',
},
page: {
flex: 1,
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
top: 0,
},
zhifu: {
height: 150,
},
flex: {
flex: 1,
},
at: {
borderWidth: 1 / PixelRatio.get(),
width: 80,
marginLeft:10,
marginRight:10,
borderColor: '#18B7FF',
height: 1,
marginTop: 10
},
date: {
textAlign: 'center',
marginBottom: 5
},
station: {
fontSize: 20
},
mp10: {
marginTop: 5,
},
btn: {
width: 60,
height: 30,
borderRadius: 3,
backgroundColor: '#FFBA27',
padding: 5,
},
btn_text: {
lineHeight: 18,
textAlign: 'center',
color: '#fff',
},
});
AppRegistry.registerComponent('ModalDemo', () => ModalDemo);
1.png
相關推薦
React Native之Modal元件實現遮罩層效果
React-Native中Modal的使用 /** * React Native App * dongtao 2017/04/22 * @flow */ import React, { Component } from 'react'; import { A
javascript+html實現遮罩層效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8">
React Native之Modal實現自定義Dialog
針對普通的彈框,React Native(RN)給我們提供了有Alert,但使用侷限性很大,沒有辦法自定義,要實現自定義的彈框,我們應該如何來實現呢,這裡提供兩種方法:第一就是native本地來實現,然後暴露給RN來條用,第二就是使用元件Modal來實現,第一種方法這裡就不
React Native之通過createStackNavigator實現攜帶引數的頁面與頁面之間的跳轉
1 實現的功能 在網上看React Native文件,我特碼就想實現一個頁面到另外一個頁面的跳轉,然後另外一個頁面怎麼獲取引數,特麼沒找到一個說清楚的,要麼太複雜,要麼說了不理解,下面是我自己寫的一個App.js檔案,實現一個Home頁面跳到另外Details頁面,並且攜
React Native 之Image 元件
1.載入網路圖片 render() { return ( <View style={styles.container} > <Image source={{uri: 'https://facebook.
html+css原始碼之實現登入彈出框遮罩層效果
在web開發中,很多網站都做了一些特別炫麗的效果,比如使用者登入彈框遮罩層效果,本文章向大家介紹css如何實現登入彈出框遮罩層效果,需要的朋友可以參考一下本文章的原始碼。 html+css實現登入彈出框遮罩層效果,原始
React Native 之View元件的回撥
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react'; import
基礎篇章:關於 React Native 之 Picker 元件的講解
今天我們就講Picker ,顧名思義就是選擇器。用法也是相當的簡單。這裡我們直接就看屬性吧。 Picker 的屬性 onValueChange function 當選擇器中的某一項被選中的時候
React Native之ViewPagerAndroid 元件
ViewPagerAndroid例項為了更好的理解,我們自己實現一個例項,效果如下:import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, ViewPagerAndroid, Tou
JS實現遮罩層
ext size UNC document osi white body opacity get /* * 顯示loading遮罩層 */ function loading() { var mask_bg = document.createElement(
js 實現遮罩層鎖屏功能
我們需要對彈出的視窗進行強調突出表現,那麼需要對周圍的元素進行遮罩。並且周圍的元素還不可以進行操作,又需要進行鎖屏。最後我們需要對重複的程式碼進行封裝。 一 介面設計 效果圖一 效果圖2 二 設定效果 1.做一個遮罩層 建立一個可以佈滿整個瀏覽器的d
lua 中實現遮罩層和遮蔽層
--遮罩層 local maskLayer = CCLayerColor:create(ccc4(0, 0, 0, 120), visibleSize.width, visibleSi
Android 實現 遮罩動畫效果
為了實現遮罩效果動畫。android本身沒有提供api ,需要自己動手實現。 將view和view的parentLy進行相反方向動畫即可實現該效果: AnimatorSet animatorSet
HTML 練習實現遮罩層
top 遮罩層 練習 :hover ctype bili title head bottom <!DOCTYPE html> <html lang="en"> <head> <meta charset=&
介面操作結果提示彈出框2--遮罩層效果
js包含了html程式碼和顯示消失的功能,忽然想起來link可以去掉css的,因為在其他html介面裡會呼叫這些css樣式 suernk.js如下: //brace.html裡的三個彈出框,為了避免呼叫麻煩,將彈出框放到js裡 //document.write("<link rel='
學習筆記3--CSS製作滑鼠放上後淡入透明遮罩層效果
transition: Internet Explorer 10、Firefox、Opera 和 Chrome 支援 transition 屬性。 Safari 支援替代的 -webkit
點選按鈕Alert彈出遮罩層效果的提示框程式碼
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"> <head> <title>經過改善優化的Alert彈出提示效果</titl
frameset巢狀的子頁面js彈出新頁面時,父頁面新增遮罩層效果
frameset巢狀的子頁面: 新增遮罩層: $(‘html’, window.parent.document).append(‘<div class=”mtDiv” style=”position: fixed;top: 0%;left: 0%;w
【CSS】- 遮罩層效果
浪費了“黃金五年”的Java程式設計師,還有救嗎? >>>
微信小程式之modal彈出框遮罩層元件——可帶文字框
modal彈出框遮罩層可實現提示資訊、驗證碼等功能 然而在官方文件已經刪除了modal的頁面,說要廢棄modal 就個人而言modal元件無法被wx.showModal完全替代。大家都知道小程式的wxml的元件可以通過改變js的值實現重新渲染,而介面是無