最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

ReactNative地址挑选器功能实现方法

来源:动视网 责编:小OO 时间:2020-11-27 20:05:19
文档

ReactNative地址挑选器功能实现方法

产品经理:“你明白吧,这里向右划可以出菜单,然后需要一个闪烁的动画,还有,我想这个tab可以拉下来,你懂吧。设计师:“别废话,把你要抄的产品给我看下。”。…;接下来,我们仿一下别人家的地址挑选器。;
推荐度:
导读产品经理:“你明白吧,这里向右划可以出菜单,然后需要一个闪烁的动画,还有,我想这个tab可以拉下来,你懂吧。设计师:“别废话,把你要抄的产品给我看下。”。…;接下来,我们仿一下别人家的地址挑选器。;
 本文主要为大家详细介绍了React Native仿地址挑选器功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

产品经理:“你明白吧,这里向右划可以出菜单,然后需要一个闪烁的动画,还有,我想这个tab可以拉下来,你懂吧?

设计师:“别废话,把你要抄的产品给我看下。”


接下来,我们仿一下别人家的地址挑选器

import React, { Component, PropTypes } from 'react';
import {
 ViewPropTypes,
 StyleSheet,
 View,
 TouchableOpacity,
 TouchableNativeFeedback,
 Platform,
 Animated,
 Text
} from 'react-native';

export default class SelectCityTabBar extends Component {
 //属性声名
 static propTypes = {
 goToPage: PropTypes.func,
 activeTab: PropTypes.number,
 tabs: PropTypes.array,
 backgroundColor: PropTypes.string,
 activeTextColor: PropTypes.string,
 inactiveTextColor: PropTypes.string,
 textStyle: Text.propTypes.style,
 tabStyle: ViewPropTypes.style,
 renderTab: PropTypes.func,
 underlineStyle: ViewPropTypes.style,
 };
 //默认属性
 static defaultProps = {
 activeTextColor: '#FA3D4F',
 inactiveTextColor: 'black',
 backgroundColor: null,
 }

 renderTab(name, page, isTabActive, onPressHandler) {
 const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
 const textColor = isTabActive ? activeTextColor : inactiveTextColor;
 const fontWeight = isTabActive ? 'bold' : 'normal';
 const viewStyle = isTabActive ? [styles.tab, { borderBottomWidth: Constant.sizepiderLarge, borderColor: Constant.colorPrimary }] : styles.tab;

 if (Platform.OS !== 'ios') {
 return <TouchableNativeFeedback
 delayPressIn={0}
 background={TouchableNativeFeedback.SelectableBackground()}
 key={name + page}
 accessible={true}
 accessibilityLabel={name}
 accessibilityTraits='button'
 onPress={() => onPressHandler(page)}
 >
 <View style={viewStyle}>
 <Text style={[{ color: textColor, fontWeight, }, textStyle,]}>
 {name}
 </Text>
 </View>
 </TouchableNativeFeedback>
 }

 return <TouchableOpacity
 key={name + page}
 accessible={true}
 accessibilityLabel={name}
 accessibilityTraits='button'
 onPress={() => onPressHandler(page)}
 >
 <View style={viewStyle}>
 <Text style={[{ color: textColor, fontWeight, }, textStyle,]}>
 {name}
 </Text>
 </View>
 </TouchableOpacity>;
 }

 render() {
 return (
 <View style={{ flexDirection: 'row', borderBottomWidth: Constant.sizepiderNormal, borderColor: Constant.colorpider }}>
 {this.props.tabs.map((name, page) => {
 const isTabActive = this.props.activeTab === page;
 const renderTab = this.props.renderTab || this.renderTab;
 return this.renderTab(name, page, isTabActive, this.props.goToPage);
 })}
 </View>
 );
 }
}



const styles = StyleSheet.create({
 tab: {
 alignItems: 'center',
 justifyContent: 'center',
 paddingBottom: 10,
 marginLeft: 10,
 },
 tabs: {
 height: 50,
 flexDirection: 'row',
 justifyContent: 'space-around',
 borderWidth: 1,
 borderTopWidth: 0,
 borderLeftWidth: 0,
 borderRightWidth: 0,
 borderColor: '#ccc',
 },
});

npm react-native-scrollable-tab-view 组件

使用方法:

import React, {Component} from 'react';
import {
 StyleSheet,
 View,
 TouchableOpacity,
 Alert,
 ScrollView,
 ART,
 TouchableHighlight,
 ListView,
 Dimensions,
 Text
} from 'react-native';

import {ReactNavComponent, Widget} from 'rn-yunxi';
import AddressSelect from '../../app-widget/address-select/index'

export default class extends React.Component {

 render() {
 return (
 <TouchableOpacity style={{flex:1, justifyContent:'center', alignItems:'center'}} onPress={() => this.openAddressSelect()}>
 <Text >地址选择</Text>
 </TouchableOpacity>
 );

 }

 openAddressSelect() {

 Widget.Popup.show( // 这边使用自己封装的modal嵌套地址选择器
 <AddressSelect
 commitFun={(area) => this.onSelectArea(area)}
 dissmissFun={() => Widget.Popup.hide()}
 />,
 {
 animationType: 'slide-up', backgroundColor: '#00000000', onMaskClose: () => {
 Widget.Popup.hide()
 }
 })
 }

 onSelectArea = (area) => {
 Log(area)
 }
};

数据类型格式

文档

ReactNative地址挑选器功能实现方法

产品经理:“你明白吧,这里向右划可以出菜单,然后需要一个闪烁的动画,还有,我想这个tab可以拉下来,你懂吧。设计师:“别废话,把你要抄的产品给我看下。”。…;接下来,我们仿一下别人家的地址挑选器。;
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top