@mpxjs/core 2.10.4-beta.12 → 2.10.4-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.4-beta.12",
3
+ "version": "2.10.4-beta.18",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -3,33 +3,37 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'
3
3
  import * as ReactNative from 'react-native'
4
4
  import Mpx from '../../index'
5
5
 
6
+ function convertToHex (color) {
7
+ try {
8
+ const intColor = ReactNative.processColor(color)
9
+ if (intColor === null || intColor === undefined) {
10
+ return null
11
+ }
12
+ // 将32位整数颜色值转换为RGBA
13
+ const r = (intColor >> 16) & 255
14
+ const g = (intColor >> 8) & 255
15
+ const b = intColor & 255
16
+ // 转换为十六进制
17
+ const hexR = r.toString(16).padStart(2, '0')
18
+ const hexG = g.toString(16).padStart(2, '0')
19
+ const hexB = b.toString(16).padStart(2, '0')
20
+ return `#${hexR}${hexG}${hexB}`
21
+ } catch (error) {
22
+ return null
23
+ }
24
+ }
25
+
26
+ const titleHeight = 44
6
27
  export function useInnerHeaderHeight (pageconfig) {
7
28
  if (pageconfig.navigationStyle === 'custom') {
8
29
  return 0
9
30
  } else {
10
31
  const safeAreaTop = useSafeAreaInsets()?.top || 0
11
- const headerHeight = safeAreaTop + getTitleHeight()
32
+ const headerHeight = safeAreaTop + titleHeight
12
33
  return headerHeight
13
34
  }
14
35
  }
15
36
 
16
- // 固定写死高度
17
- function getTitleHeight () {
18
- return 44
19
- }
20
-
21
- // 计算颜色亮度
22
- const getColorBrightness = (color) => {
23
- const processedColor = ReactNative.processColor(color)
24
- if (typeof processedColor === 'number') {
25
- const r = (processedColor >> 16) & 255
26
- const g = (processedColor >> 8) & 255
27
- const b = processedColor & 255
28
- return (r * 299 + g * 587 + b * 114) / 1000
29
- }
30
- return 0
31
- }
32
-
33
37
  const styles = ReactNative.StyleSheet.create({
34
38
  header: {
35
39
  elevation: 3
@@ -54,10 +58,24 @@ const styles = ReactNative.StyleSheet.create({
54
58
  },
55
59
  title: {
56
60
  fontSize: 17,
57
- fontWeight: 600
61
+ fontWeight: 600,
62
+ width: '60%',
63
+ textAlign: 'center'
58
64
  }
59
65
  })
60
-
66
+ const NavColor = {
67
+ White: '#ffffff',
68
+ Black: '#000000'
69
+ }
70
+ // navigationBarTextStyle只支持黑白'white'/'black
71
+ const validBarTextStyle = (textStyle) => {
72
+ const textStyleColor = convertToHex(textStyle)
73
+ if (textStyle && [NavColor.White, NavColor.Black].includes(textStyleColor)) {
74
+ return textStyleColor
75
+ } else {
76
+ return NavColor.White
77
+ }
78
+ }
61
79
  export function innerNav ({ props, navigation }) {
62
80
  const { pageConfig } = props
63
81
  const [innerPageConfig, setPageConfig] = useState(pageConfig || {})
@@ -65,16 +83,17 @@ export function innerNav ({ props, navigation }) {
65
83
  const newConfig = Object.assign({}, innerPageConfig, config)
66
84
  setPageConfig(newConfig)
67
85
  }
68
-
69
86
  const isCustom = innerPageConfig.navigationStyle === 'custom'
70
- if (isCustom) return null
71
- const safeAreaTop = useSafeAreaInsets()?.top || 0
72
-
73
- // 回退按钮的颜色,根据背景色的亮度来进行调节
74
- const backButtonColor = useMemo(() => {
75
- return getColorBrightness(innerPageConfig.navigationBarBackgroundColor) > 128 ? '#000000' : '#ffffff'
76
- }, [innerPageConfig.navigationBarBackgroundColor])
87
+ const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle])
88
+ // 状态栏的颜色
89
+ const statusBarElement = createElement(ReactNative.StatusBar, {
90
+ translucent: true,
91
+ backgroundColor: 'transparent',
92
+ barStyle: (navigationBarTextStyle === NavColor.White) ? 'light-content' : 'dark-content' // 'default'/'light-content'/'dark-content'
93
+ })
77
94
 
95
+ if (isCustom) return statusBarElement
96
+ const safeAreaTop = useSafeAreaInsets()?.top || 0
78
97
  // 假设是栈导航,获取栈的长度
79
98
  const stackLength = navigation.getState()?.routes?.length
80
99
  // 用于外部注册打开RN容器之前的栈长度
@@ -87,7 +106,8 @@ export function innerNav ({ props, navigation }) {
87
106
  onPress: () => { navigation.goBack() }
88
107
  }, createElement(ReactNative.Image, {
89
108
  source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
90
- style: [styles.backButtonImage, { tintColor: backButtonColor }]
109
+ // 回退按钮的颜色与设置的title文案颜色一致
110
+ style: [styles.backButtonImage, { tintColor: navigationBarTextStyle }]
91
111
  }))
92
112
  : null
93
113
 
@@ -97,12 +117,14 @@ export function innerNav ({ props, navigation }) {
97
117
  backgroundColor: innerPageConfig.navigationBarBackgroundColor || '#000000'
98
118
  }]
99
119
  },
120
+ statusBarElement,
100
121
  createElement(ReactNative.View, {
101
122
  style: styles.headerContent,
102
- height: getTitleHeight()
123
+ height: titleHeight
103
124
  }, backElement,
104
125
  createElement(ReactNative.Text, {
105
- style: [styles.title, { color: innerPageConfig.navigationBarTextStyle || 'white' }]
126
+ style: [styles.title, { color: navigationBarTextStyle }],
127
+ numberOfLines: 1
106
128
  }, innerPageConfig.navigationBarTitleText?.trim() || ''))
107
129
  )
108
130
  }