Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. import React from 'react'
  2. import {
  3. Text,
  4. TextStyle,
  5. View,
  6. ViewStyle,
  7. Image,
  8. ImageStyle,
  9. TouchableOpacity,
  10. Platform,
  11. Animated,
  12. } from 'react-native'
  13. import {
  14. Colors,
  15. windowWidth,
  16. windowHeight,
  17. } from '../../core/theme'
  18. //import { Dispatch } from 'redux'
  19. import { connectAdv } from '../../core/store/connectAdv'
  20. import { Profile } from '../../core/api/generated/dto/CommonResponse.g'
  21. import { BaseReduxComponent } from '../../core/BaseComponent'
  22. import { IAppState } from '../../core/store/appState'
  23. import { styleSheetCreate } from '../utils'
  24. import { ImageResources } from '../../common/ImageResources.g'
  25. import { localization as l } from '../../common/localization/localization'
  26.  
  27. interface IStateProps {
  28. user: Profile
  29. }
  30.  
  31. interface IDispatchProps {
  32.  
  33. }
  34.  
  35. interface IState {
  36. isOpened: boolean
  37. animation: any
  38. }
  39.  
  40. interface IProps {
  41. statusSelect: boolean
  42. itemSelect(status: boolean): void
  43. levelButton: string
  44. }
  45.  
  46. @connectAdv(
  47. (state: IAppState): IStateProps => ({
  48. user: state.common.user,
  49. })
  50. )
  51. export class DropDown extends BaseReduxComponent<IStateProps, IDispatchProps, IState, IProps> {
  52.  
  53. objLevels: { [key: string]: string } = {
  54. '7': 'A0',
  55. '8': 'A1',
  56. '9': 'A2',
  57. '10': 'B1',
  58. '11': 'B2',
  59. '12': 'C1',
  60. '13': 'C2',
  61. }
  62.  
  63. state = {
  64. isOpened: false,
  65. animation: new Animated.Value(0),
  66. }
  67.  
  68. shouldComponentUpdate(nextProps:any, nextState:any){
  69. if(this.props.statusSelect !== nextProps.statusSelect){
  70. this.props.itemSelect(false)
  71. this.closeDropDown()
  72. }
  73. return true
  74. }
  75.  
  76. toggleDropDown = (): void => {
  77. if (this.state.isOpened || this.props.statusSelect) {
  78. this.closeDropDown()
  79. } else {
  80. this.openDropDown()
  81. }
  82. }
  83.  
  84. openDropDown = (): void => {
  85. Animated.timing(this.state.animation, {
  86. toValue: 1,
  87. duration: 200,
  88. }).start(() => this.setState({
  89. isOpened: true
  90. }))
  91. }
  92.  
  93. closeDropDown = (): void => {
  94. this.setState({ isOpened: false }, () => {
  95. Animated.timing(this.state.animation, {
  96. toValue: 0,
  97. duration: 200,
  98. }).start()
  99. })
  100. }
  101.  
  102.  
  103. render(): JSX.Element {
  104.  
  105. console.log('levelDROPDOWN>>>>>' , this.props.levelButton)
  106. const { userLevel } = this.stateProps.user
  107. const userLevelDefault = this.objLevels[userLevel]
  108. const selectedLevel = this.props.levelButton || userLevelDefault
  109.  
  110. const showListStyle = {
  111. height: this.state.animation.interpolate({
  112. inputRange: [0, 1],
  113. outputRange: [0, windowWidth * 1.1],
  114. })
  115. }
  116.  
  117. return (
  118. //TODO: развернуть треугольник при анимации
  119. <>
  120. <TouchableOpacity onPress={this.toggleDropDown}>
  121. <View style={styles.levelDropDown} >
  122. <Text style={styles.levelTitle}>
  123. {l.common.level} {selectedLevel}
  124. </Text>
  125. <Image
  126. style={styles.dropDownTriangle}
  127. source={ImageResources.dropDownTriangle}
  128. />
  129. </View>
  130. </TouchableOpacity>
  131. {
  132. //TODO: перелать стили на флаттен
  133. <Animated.View style={[styles.levelsList, showListStyle]}>
  134. {this.state.isOpened ? this.props.children : null}
  135. </Animated.View>
  136. }
  137. </>
  138. )
  139. }
  140.  
  141. }
  142.  
  143. const styles = styleSheetCreate({
  144. levelDropDown: {
  145. justifyContent: 'center',
  146. alignItems: 'center',
  147. backgroundColor: Colors.white,
  148. borderRadius: windowWidth * .03,
  149. padding: windowWidth * .04,
  150. margin: windowHeight * .02,
  151. marginBottom: windowWidth * .06,
  152. borderWidth: windowWidth * .003,
  153. borderColor: Colors.greyDB,
  154. borderStyle: 'solid',
  155. zIndex: 400,
  156. } as ViewStyle,
  157. levelTitle: {
  158. color: Colors.dark5E,
  159. fontSize: windowWidth * .039,
  160. fontWeight: '400',
  161. } as TextStyle,
  162. levelsList: {
  163. position: 'absolute',
  164. zIndex: 20,
  165. backgroundColor: Colors.white,
  166. marginTop: windowWidth * .21,
  167. marginHorizontal: windowWidth * .04,
  168. width: windowWidth * .92,
  169. ...Platform.select({
  170. ios: {
  171. shadowRadius: 15,
  172. shadowOpacity: 0.3,
  173. shadowOffset: { width: 1, height: 4 },
  174. },
  175. android: {
  176. elevation: 10,
  177. }}),
  178. },
  179. dropDownTriangle: {
  180. position: 'absolute',
  181. width: windowWidth * .02,
  182. height: windowWidth * .015,
  183. right: windowWidth * .06,
  184. } as ImageStyle,
  185. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement