Toolbar.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React, { useEffect, useState } from 'react';
  2. import { Pressable, StyleSheet, View } from 'react-native';
  3. import TopChargeBackground from '../icons/TopChargeBackground';
  4. import HeaderTitle from './HeaderTitle';
  5. export const BackButton = ({style=Styles.backIcon, color=pageTitleTint, children, onPress}) => {
  6. return (
  7. <Pressable
  8. style={({pressed }) => [
  9. (pressed && isIOS) && {
  10. opacity: 0.5
  11. },
  12. style
  13. ]}
  14. android_ripple = {rippleLessIcon}
  15. onPress={() => {
  16. if (onPress) {
  17. onPress();
  18. } else {
  19. goBack();
  20. }
  21. }}>
  22. { children
  23. ? children
  24. : <BackIcon color={color}/>
  25. }
  26. </Pressable>
  27. )
  28. }
  29. export const BackIcon = ({color=pageTitleTint}) => {
  30. return (
  31. <MaterialIcons
  32. name={isIOS ? 'arrow-back-ios' : 'arrow-back'}
  33. size={isIOS ? 20 : 24}
  34. color={color}/>
  35. )
  36. }
  37. export const StationBack = ({bottom = 24, scale=1.0}) => {
  38. return (
  39. // <Image
  40. // style={{
  41. // right: 0,
  42. // bottom: bottom,
  43. // width: 125.8,
  44. // height: 137.64,
  45. // position: 'absolute'
  46. // }}
  47. // source={require('../images/charge/bg-top-station.png')}/>
  48. <View
  49. style={{
  50. right: 0,
  51. bottom: bottom,
  52. width: 127.5 * scale,
  53. height: 136.67 * scale,
  54. position: 'absolute',
  55. alignItems: 'flex-end'
  56. }}>
  57. <TopChargeBackground width={127.5 * scale} height={136.67 * scale}/>
  58. </View>
  59. );
  60. }
  61. export default Toolbar = ({
  62. style=Styles.toolbar,
  63. title,
  64. scope,
  65. showBack=true,
  66. rightIcon,
  67. onBackPress,
  68. height=toolbarSize,
  69. children
  70. }) => {
  71. const [viewStyle, setStyle] = useState({})
  72. useEffect(() => {
  73. if (isIOS) {
  74. console.log("statusHeight", statusHeight)
  75. setStyle({
  76. height: height + statusHeight,
  77. paddingTop: statusHeight
  78. })
  79. }
  80. }, []);
  81. if (children) {
  82. return (
  83. <View style={[style, viewStyle]}>
  84. {children}
  85. </View>
  86. )
  87. } else {
  88. return (
  89. <View style={[style, viewStyle]}>
  90. { showBack &&
  91. <BackButton onPress={onBackPress}/>
  92. }
  93. <HeaderTitle scope={scope} title={title} style={Styles.titleText}/>
  94. { rightIcon
  95. ? rightIcon()
  96. : showBack
  97. ? <View style={Styles.backIcon}>
  98. <MaterialIcons
  99. name={'arrow-back-ios'}
  100. size={16}
  101. color={'transparent'} />
  102. </View>
  103. : <></>
  104. }
  105. </View>
  106. )
  107. }
  108. }
  109. export const Styles = StyleSheet.create({
  110. toolbar: {
  111. height: toolbarSize + statusHeight,
  112. paddingLeft: isIOS ? 0 : 2,
  113. paddingRight: isIOS ? 0 : 2,
  114. paddingTop: statusHeight,
  115. alignItems: 'center',
  116. flexDirection: 'row',
  117. justifyContent: 'center',
  118. backgroundColor: colorPrimaryDark
  119. },
  120. backIcon: {
  121. width: 48,
  122. height: 48,
  123. zIndex: 2,
  124. alignItems: 'center',
  125. justifyContent: 'center'
  126. },
  127. content: {
  128. flex: 1,
  129. paddingRight: 48,
  130. alignItems: 'center'
  131. },
  132. logo: {
  133. width:123.8,
  134. height: 38.95
  135. },
  136. rightIcon: {
  137. width: 22,
  138. height: 22,
  139. opacity: 0.9
  140. },
  141. iconOpacity: {
  142. opacity: 0.9
  143. },
  144. titleText: {
  145. flex: 1,
  146. color: pageTitleTint,
  147. paddingLeft: isIOS ? 8 : 16,
  148. textAlign: isIOS ? 'center' : 'left'
  149. }
  150. });