説明なし

LearnLevelViewController.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. * Created by zack on 2018/4/26.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity,
  9. Platform
  10. } from 'react-native'
  11. import React, {Component} from 'react'
  12. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  13. import {Navigation} from 'react-native-navigation'
  14. export default class LearnLevelViewController extends Component {
  15. constructor(props) {
  16. super(props)
  17. this.state = {
  18. selectedSegmentIndex: 0,
  19. selectedLearnLevelIndex: 0,
  20. selectedCategoryIndex: 0,
  21. isPush: props.isPush
  22. }
  23. }
  24. componentDidMount() {
  25. }
  26. goToTabar() {
  27. const BaseNavigatorStyle = {
  28. drawUnderNavBar: true,
  29. drawUnderTabBar: true,
  30. navBarHidden: true,
  31. navBarBackgroundColor: '#ffffff',
  32. navBarButtonColor: '#000000',
  33. navBarTranslucent: Platform.OS === 'ios' ? true : false,
  34. navBarTitleTextCentered: 'center'
  35. }
  36. Navigation.startTabBasedApp({
  37. tabs: [
  38. {
  39. label: '玩双语', // tab label as appears under the icon in iOS (optional)
  40. screen: 'PlayViewController', // unique ID registered with Navigation.registerScreen
  41. icon: require('../../resources/images/TabBar/play.png'), // local image asset for the tab icon unselected state (optional on iOS)
  42. selectedIcon: require('../../resources/images/TabBar/icon玩双语hover.png'), // local image asset for the tab icon selected state (optional, iOS only. On Android, Use `tabBarSelectedButtonColor` instead)
  43. title: '', // title of the screen as appears in the nav bar (optional)
  44. navigatorStyle: BaseNavigatorStyle
  45. },
  46. {
  47. label: '学双语', // tab label as appears under the icon in iOS (optional)
  48. screen: 'LearnViewController', // unique ID registered with Navigation.registerScreen
  49. icon: require('../../resources/images/TabBar/icon学双语.png'), // local image asset for the tab icon unselected state (optional on iOS)
  50. selectedIcon: require('../../resources/images/TabBar/icon学双语hover.png'), // local image asset for the tab icon selected state (optional, iOS only. On Android, Use `tabBarSelectedButtonColor` instead)
  51. title: '单词', // title of the screen as appears in the nav bar (optional)
  52. subtitle: "2/10",
  53. navigatorStyle: BaseNavigatorStyle
  54. },
  55. {
  56. label: Platform.OS === 'ios' ? '' : '视频', // tab label as appears under the icon in iOS (optional)
  57. screen: 'CameraViewController', // unique ID registered with Navigation.registerScreen
  58. icon: require('../../resources/images/TabBar/camera.png'), // local image asset for the tab icon unselected state (optional on iOS)
  59. selectedIcon: require('../../resources/images/TabBar/camera.png'), // local image asset for the tab icon selected state (optional, iOS only. On Android, Use `tabBarSelectedButtonColor` instead)
  60. // title: '', // title of the screen as appears in the nav bar (optional)
  61. navigatorStyle: BaseNavigatorStyle,
  62. iconInsets: { // add this to change icon position (optional, iOS only).
  63. top: 0, // optional, default is 0.
  64. left: 0, // optional, default is 0.
  65. bottom: -12, // optional, default is 0.
  66. right: 0 // optional, default is 0.
  67. },
  68. },
  69. {
  70. label: '社区', // tab label as appears under the icon in iOS (optional)
  71. screen: 'CommunityViewController', // unique ID registered with Navigation.registerScreen
  72. icon: require('../../resources/images/TabBar/icon社区.png'), // local image asset for the tab icon unselected state (optional on iOS)
  73. selectedIcon: require('../../resources/images/TabBar/icon社区.png'), // local image asset for the tab icon selected state (optional, iOS only. On Android, Use `tabBarSelectedButtonColor` instead)
  74. title: '', // title of the screen as appears in the nav bar (optional)
  75. navigatorStyle: BaseNavigatorStyle
  76. },
  77. {
  78. label: '聊天', // tab label as appears under the icon in iOS (optional)
  79. screen: 'ChatViewController', // unique ID registered with Navigation.registerScreen
  80. icon: require('../../resources/images/TabBar/chat.png'), // local image asset for the tab icon unselected state (optional on iOS)
  81. selectedIcon: require('../../resources/images/TabBar/chathover.png'), // local image asset for the tab icon selected state (optional, iOS only. On Android, Use `tabBarSelectedButtonColor` instead)
  82. title: '', // title of the screen as appears in the nav bar (optional)
  83. navigatorStyle: BaseNavigatorStyle
  84. },
  85. ],
  86. tabsStyle: {
  87. // navBarBackgroundColor: '#377bb5',
  88. // navBarTextColor: '#000000',
  89. // navBarTranslucent: Platform.OS === 'ios' ? true : false,
  90. // drawUnderNavBar: true,
  91. //navBarTextColor: 'white',
  92. // navBarButtonColor: 'white',
  93. // statusBarTextColorScheme: 'light',
  94. // drawUnderTabBar: true,
  95. // statusBarColor: '#0281c5',
  96. // navBarSubtitleColor: 'white',
  97. tabBarSelectedButtonColor: '#f01414', // iOS only. change the color of the selected tab text
  98. tabBarButtonColor: '#333333',
  99. tabBarLabelColor: '#333333', // iOS only. change the color of tab text
  100. tabBarSelectedLabelColor: '#f01414',
  101. },
  102. appStyle: {
  103. forceTitlesDisplay: true,
  104. tabBarSelectedButtonColor: '#f01414', // iOS only. change the color of the selected tab text
  105. tabBarButtonColor: '#333333',
  106. tabBarLabelColor: '#333333', // iOS only. change the color of tab text
  107. tabBarSelectedLabelColor: '#f01414',
  108. }
  109. })
  110. }
  111. ChangeLearnLevelAction(index) {
  112. this.setState({selectedLearnLevelIndex: index})
  113. }
  114. renderMenuViewItem() {
  115. let menus = []
  116. let menuTitles = ["综合", "单词","综合", "句子","语法", "听力","翻译"]
  117. for (let i = 0; i < menuTitles.length; i ++) {
  118. let title = menuTitles[i]
  119. let item = (
  120. <TouchableOpacity onPress={() => {
  121. this.setState({selectedCategoryIndex: i})
  122. }} style={[styles.BaseButtonView, {marginTop: i < 3 ? 0 : 12}, {backgroundColor: this.state.selectedCategoryIndex === i ? '#71c135' : '#e5e5e5'}]} key = {i}>
  123. <Text style={[styles.SegmentControlText, {color: this.state.selectedCategoryIndex === i ? '#ffffff' : '#666666'}]}>{title}</Text>
  124. </TouchableOpacity>
  125. )
  126. menus.push(item)
  127. }
  128. return menus
  129. }
  130. render() {
  131. let leftSegmentBorderColor = '#71c135'
  132. let leftSegmentBackgroundColor = "#71c135"
  133. let rightSegmentBorderColor = '#ffffff'
  134. let rightSegmentBackgroundColor = "#71c135"
  135. if (this.state.selectedSegmentIndex === 0) {
  136. leftSegmentBackgroundColor = "#71c135"
  137. rightSegmentBorderColor = '#71c135'
  138. rightSegmentBackgroundColor = "#ffffff"
  139. }else {
  140. leftSegmentBackgroundColor = "#ffffff"
  141. rightSegmentBorderColor = '#71c135'
  142. rightSegmentBackgroundColor = "#71c135"
  143. }
  144. return(
  145. <View style={styles.View}>
  146. <View style={styles.SegmentControlBgView}>
  147. <TouchableOpacity onPress={() => {
  148. this.setState({selectedSegmentIndex: 0})
  149. }} style={[styles.SegmentControlLeftView, {backgroundColor: leftSegmentBackgroundColor, borderLeftColor: leftSegmentBorderColor, borderTopColor: leftSegmentBorderColor, borderBottomColor: leftSegmentBorderColor}]}>
  150. <Text style={[styles.SegmentControlText, {color: this.state.selectedSegmentIndex === 0 ? '#ffffff' : '#71c135'}]}>{'学英文'}</Text>
  151. </TouchableOpacity>
  152. <TouchableOpacity onPress={() => {
  153. this.setState({selectedSegmentIndex: 1})
  154. }} style={[styles.SegmentControlRightView,{ borderRightColor: rightSegmentBorderColor, borderTopColor: rightSegmentBorderColor, borderBottomColor: rightSegmentBorderColor}, {backgroundColor: rightSegmentBackgroundColor}]}>
  155. <Text style={[styles.SegmentControlText, {color: this.state.selectedSegmentIndex === 1 ? '#ffffff' : '#71c135'}]}>{'学中文'}</Text>
  156. </TouchableOpacity>
  157. </View>
  158. <View style={styles.LearnLevelBgView}>
  159. <TouchableOpacity onPress={() => {
  160. this.ChangeLearnLevelAction(0)
  161. }} style={[styles.BaseButtonView, {backgroundColor: this.state.selectedLearnLevelIndex === 0 ? '#71c135' : '#e5e5e5'}]}>
  162. <Text style={[styles.SegmentControlText, {color: this.state.selectedLearnLevelIndex === 0 ? '#ffffff' : '#666666'}]}>{'初级'}</Text>
  163. </TouchableOpacity>
  164. <TouchableOpacity onPress={() => {
  165. this.ChangeLearnLevelAction(1)
  166. }} style={[styles.BaseButtonView, {backgroundColor: this.state.selectedLearnLevelIndex === 1 ? '#71c135' : '#e5e5e5'}]}>
  167. <Text style={[styles.SegmentControlText, {color: this.state.selectedLearnLevelIndex === 1 ? '#ffffff' : '#666666'}]}>{'中级'}</Text>
  168. </TouchableOpacity>
  169. <TouchableOpacity onPress={() => {
  170. this.ChangeLearnLevelAction(2)
  171. }} style={[styles.BaseButtonView, {backgroundColor: this.state.selectedLearnLevelIndex === 2 ? '#71c135' : '#e5e5e5'}]}>
  172. <Text style={[styles.SegmentControlText, {color: this.state.selectedLearnLevelIndex === 2 ? '#ffffff' : '#666666'}]}>{'高级'}</Text>
  173. </TouchableOpacity>
  174. </View>
  175. <View style={styles.CategoryBgView}>
  176. {this.renderMenuViewItem()}
  177. </View>
  178. <TouchableOpacity onPress={() => {
  179. if (this.state.isPush) {
  180. this.props.navigator.dismissModal()
  181. }else {
  182. this.goToTabar()
  183. }
  184. }} style={[styles.BeginButtonView,]}>
  185. <Text style={{fontSize: 18, color: '#ffffff'}}>{this.state.isPush === true ? '完成' : '开始' }</Text>
  186. </TouchableOpacity>
  187. </View>
  188. )
  189. }
  190. }
  191. const styles = StyleSheet.create({
  192. View: {
  193. width: ScreenDimensions.width,
  194. height: ScreenDimensions.height,
  195. backgroundColor: 'white',
  196. alignItems: 'center'
  197. },
  198. SegmentControlBgView: {
  199. marginTop: 40 + (Platform.OS === 'ios'? 20 : 0),
  200. width: 200,
  201. height: 40,
  202. flexDirection: 'row',
  203. alignItems: 'center',
  204. // borderRadius: 20,
  205. // borderColor: '#71c135',
  206. // borderWidth: 1
  207. },
  208. SegmentControlLeftView: {
  209. width: 100,
  210. height: 40,
  211. justifyContent: 'center',
  212. alignItems: 'center',
  213. borderTopLeftRadius: 20,
  214. borderBottomLeftRadius: 20,
  215. borderLeftWidth: 1,
  216. borderTopWidth: 1,
  217. borderBottomWidth: 1,
  218. },
  219. SegmentControlRightView: {
  220. width: 100,
  221. height: 40,
  222. justifyContent: 'center',
  223. alignItems: 'center',
  224. borderTopRightRadius: 20,
  225. borderBottomRightRadius: 20,
  226. borderRightWidth: 1,
  227. borderTopWidth: 1,
  228. borderBottomWidth: 1,
  229. },
  230. SegmentControlText: {
  231. fontSize: 18,
  232. },
  233. BaseButtonView: {
  234. width: 80,
  235. height: 40,
  236. justifyContent: 'center',
  237. alignItems: 'center',
  238. borderRadius: 6,
  239. backgroundColor: '#e5e5e5'
  240. },
  241. LearnLevelBgView: {
  242. marginTop: 30,
  243. width: 260,
  244. height: 40,
  245. flexDirection: 'row',
  246. justifyContent: 'space-between',
  247. alignItems: 'center',
  248. },
  249. CategoryBgView: {
  250. marginTop: 30,
  251. width: 260,
  252. flexDirection: 'row',
  253. justifyContent: 'space-between',
  254. flexWrap: 'wrap'
  255. },
  256. BeginButtonView: {
  257. position: 'absolute',
  258. width: ScreenDimensions.width - 30,
  259. height: 48,
  260. borderRadius: 24,
  261. justifyContent: 'center',
  262. alignItems: 'center',
  263. left: 15,
  264. bottom: 18,
  265. backgroundColor: '#71c135'
  266. }
  267. })