react-native 二级菜单制作
2016-12-03 13:38
741 查看
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
import React, {
Component
} from 'react';
import {
StyleSheet,
Text,
ScrollView,
Image,
ListView,
TouchableOpacity,
View,
InteractionManager,
RefreshControl,
Navigator,
} from 'react-native';
import {
// Admin,
} from '../actions/adminAction';
import Common from '../common/common';
import Loading from '../common/loading';
import LoadMoreFooter from '../common/loadMoreFooter';
import HeaderView from '../common/headerView';
import BaseComponent from '../common/baseComponent';
import Icon from 'react-native-vector-icons/FontAwesome';
let titleName = '管理';
let list = ['一级菜单一', '一级菜单二', '一级菜单三'];
let tag = "";
let list2 = ['submenu1', 'submenu2', 'submenu3'];
class Admin extends BaseComponent {
constructor(props) {
super(props); //这一句不能省略,照抄即可
// debugger
this.state = {
listExpand:[false,false,false],//true表示有数据更新
};
}
renderMenuList(list) {
return list.map((item, i) => this.renderItem(item, i));
}
onPressItem(i){
let l=this.state.listExpand;
l[i]=!l[i];
this.setState({listExpand:l});
}
renderItem(item, i) {
return (
//<View key={i}><Text>{item}</Text></View> caret-down
<View key={i}>
<TouchableOpacity
activeOpacity={0.75}
onPress={this.onPressItem.bind(this,i) }
>
<View style={styles.itemContainer} >
<Icon color="gray" size={30} name={this.state.listExpand[i]?'caret-down':'caret-right'} />
<Text>{item}</Text>
</View>
</TouchableOpacity>
{this.state.listExpand[i]?this.renderSubMenuList(list2):null}
</View>
);
}
renderSubMenuList(list2) {
return list2.map((item, i) => this.renderSubItem(item, i));
}
renderSubItem(item, i) {
return (
//<View key={i}><Text>{item}</Text></View>
<View style={styles.itemContainer} key={i}>
<Text>{item}</Text>
<Icon color="gray" size={30} name='angle-right' />
</View>
);
}
render() {
//解构获取上一层的属性Home,rowDate,来自于HomeContainer
//const { Home,rowDate } = this.props;
// tag = rowDate;
// console.log(this.props);
// debugger
//let homeList = Home.HomeList;
return (
<View>
<HeaderView
titleView={titleName}
leftIcon={tag ? 'angle-left' : null}
/>
<ScrollView contentContainerStyle={styles.contentContainer}>
{this.renderMenuList(list)}
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
contentContainer: {
paddingBottom: 20,
},
center: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
itemContainer: {
width: Common.window.width - 20,
height: 50,
paddingLeft: 10,
paddingRight: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
backgroundColor: 'white',
borderBottomColor: '#ccc',
borderBottomWidth: 0.5,
},
});
module.exports = Admin;
---------------------------
headerView.js
/**
* Created by ljunb on 16/5/8.
* 导航栏标题
*/
import React from 'react';
import {
StyleSheet,
View,
Text,
Image,
TouchableOpacity,
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import Common from '../common/common';
export default class Header extends React.Component {
render() {
let NavigationBar = [];
// 左边图片按钮
if (this.props.leftIcon != undefined) {
NavigationBar.push(
<TouchableOpacity
key={'leftIcon'}
activeOpacity={0.75}
style={styles.leftIcon}
onPress={this.props.leftIconAction}
>
<Icon color="white" size={30} name={this.props.leftIcon} />
</TouchableOpacity>
)
}
// 标题,没有用!?
// if (this.props.title != undefined) {
// NavigationBar.push(
// <Text key={'title'} style={styles.title}>{this.props.title}</Text>
// )
// }
// 自定义标题View
if (this.props.titleView != undefined) {
// let Component = this.props.titleView;
NavigationBar.push(
<View key={'titleView'} style={styles.titleViewContainer}>
<Text style={styles.titleView}>{this.props.titleView}</Text>
</View>
)
}
return (
<View style={styles.navigationBarContainer}>
{NavigationBar}
</View>
)
}
}
const styles = StyleSheet.create({
navigationBarContainer: {
width: Common.window.width,
marginTop: 0,
flexDirection: 'row',
height: 44,
// justifyContent: 'center',
// alignItems: 'center',
backgroundColor: '#2e8b57',
borderBottomColor: '#ccc',
borderBottomWidth: 0.5,
// backgroundColor: 'white'
},
title: {
fontSize: 15,
marginLeft: 15,
},
titleViewContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
titleView: {
fontSize: 15,
color: 'white'
},
leftIcon: {
width: 40,
justifyContent: 'center',
alignItems: 'center',
},
})
相关文章推荐
- 使用DIV+CSS制作二级导航菜单(横向)
- 菜单-二级菜单的制作
- 我的ASP之旅—二级联动菜单制作
- ReactNative制作Component控件并且复用(二)
- Javascript制作伸缩的二级菜单
- Jquery+ajax+xml制作二级联动菜单
- 制作鼠标悬停二级菜单时,jQuery鼠标同时移出两个区域的判断
- cocos2dx-lua使用UIListView制作二级折叠菜单
- js实验2.(2)制作二级菜单
- ReactNative学习实例(六)DrawerLayoutAndroid(侧滑菜单)
- js二级菜单的制作(有动画)
- js入门·表单元素(select下拉列表)制作二级联动菜单和网站导航 .txt
- DIV+CSS制作二级横向弹出菜单,略简单
- css 制作的三级菜单也可以当做二级菜单使用
- js入门·表单元素(select下拉列表)制作二级联动菜单和网站导航
- react-native使用react-art制作SVG动画
- javascript实现二级级联菜单的简单制作
- 悬浮显示隐藏二级菜单与小三角制作
- js入门·表单元素(select下拉列表)制作二级联动菜单和网站导航
- [教程] React Native基础实战(1)—— 制作一个简单的按钮