Toolbar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. setStyle({
  75. height: height + statusHeight,
  76. paddingTop: statusHeight
  77. })
  78. }
  79. }, []);
  80. if (children) {
  81. return (
  82. <View style={[style, viewStyle]}>
  83. {children}
  84. </View>
  85. )
  86. } else {
  87. return (
  88. <View style={[style, viewStyle]}>
  89. { showBack &&
  90. <BackButton onPress={onBackPress}/>
  91. }
  92. <HeaderTitle scope={scope} title={title} style={Styles.titleText}/>
  93. { rightIcon
  94. ? rightIcon()
  95. : showBack
  96. ? <View style={Styles.backIcon}>
  97. <MaterialIcons
  98. name={'arrow-back-ios'}
  99. size={16}
  100. color={'transparent'} />
  101. </View>
  102. : <></>
  103. }
  104. </View>
  105. )
  106. }
  107. }
  108. export const Styles = StyleSheet.create({
  109. toolbar: {
  110. height: toolbarSize + statusHeight,
  111. paddingLeft: isIOS ? 0 : 2,
  112. paddingRight: isIOS ? 0 : 2,
  113. paddingTop: statusHeight,
  114. alignItems: 'center',
  115. flexDirection: 'row',
  116. justifyContent: 'center',
  117. backgroundColor: colorPrimaryDark
  118. },
  119. backIcon: {
  120. width: 48,
  121. height: 48,
  122. zIndex: 2,
  123. alignItems: 'center',
  124. justifyContent: 'center'
  125. },
  126. content: {
  127. flex: 1,
  128. paddingRight: 48,
  129. alignItems: 'center'
  130. },
  131. logo: {
  132. width:123.8,
  133. height: 38.95
  134. },
  135. rightIcon: {
  136. width: 22,
  137. height: 22,
  138. opacity: 0.9
  139. },
  140. iconOpacity: {
  141. opacity: 0.9
  142. },
  143. titleText: {
  144. flex: 1,
  145. color: pageTitleTint,
  146. paddingLeft: isIOS ? 8 : 16,
  147. textAlign: isIOS ? 'center' : 'left'
  148. }
  149. });