create-vite-taro 0.2.1 → 0.2.2
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,8 @@
|
|
|
1
1
|
import Taro from 'virtual:taro/api'
|
|
2
2
|
import { useState } from 'react'
|
|
3
3
|
|
|
4
|
+
const isWechatTarget = import.meta.env.VITE_PLUGIN_TARO_TARGET === 'wx'
|
|
5
|
+
|
|
4
6
|
interface NavigationBarNavInfo {
|
|
5
7
|
height: number
|
|
6
8
|
top: number
|
|
@@ -44,7 +46,7 @@ function createFallbackMenuInfo(screenWidth: number): NavigationBarMenuInfo {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
function getMenuInfo(screenWidth: number): NavigationBarMenuInfo {
|
|
47
|
-
if (
|
|
49
|
+
if (isWechatTarget) {
|
|
48
50
|
const menuButtonInfo = Taro.getMenuButtonBoundingClientRect()
|
|
49
51
|
if (menuButtonInfo.width > 0 && menuButtonInfo.height > 0) return menuButtonInfo
|
|
50
52
|
}
|
|
@@ -55,7 +57,7 @@ function getMenuInfo(screenWidth: number): NavigationBarMenuInfo {
|
|
|
55
57
|
export function initNavigationBar(): NavigationBarInfo {
|
|
56
58
|
const windowInfo = Taro.getWindowInfo()
|
|
57
59
|
const screenWidth = windowInfo.screenWidth || 375
|
|
58
|
-
const statusBarHeight =
|
|
60
|
+
const statusBarHeight = isWechatTarget ? (windowInfo.statusBarHeight ?? 44) : 0
|
|
59
61
|
const menuInfo = getMenuInfo(screenWidth)
|
|
60
62
|
const menuButtonStatusBarGap = Math.max(0, menuInfo.top - statusBarHeight)
|
|
61
63
|
const navBarHeight = menuButtonStatusBarGap * 2 + menuInfo.height + statusBarHeight
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import Taro from 'virtual:taro/api'
|
|
2
2
|
import { Button, Text, View } from 'virtual:taro/components'
|
|
3
|
-
import { NavigationBar } from
|
|
3
|
+
import { NavigationBar } from '../../components/navigation-bar/navigation-bar.tsx'
|
|
4
4
|
|
|
5
5
|
function IndexPage() {
|
|
6
6
|
return (
|
|
7
7
|
<View className="flex flex-col h-screen overflow-hidden">
|
|
8
|
-
<NavigationBar title=
|
|
8
|
+
<NavigationBar title="Vite Taro App" />
|
|
9
9
|
<View className="flex-1 flex items-center justify-center bg-slate-50 px-6 py-12">
|
|
10
10
|
<View className="rounded-3xl bg-white p-6 shadow-sm">
|
|
11
11
|
<Text className="block text-2xl font-semibold text-slate-950">Vite + Taro</Text>
|
|
@@ -15,7 +15,7 @@ function IndexPage() {
|
|
|
15
15
|
<Button
|
|
16
16
|
className="mt-6 rounded-xl bg-blue-600 px-4 py-2 text-white"
|
|
17
17
|
onClick={() => {
|
|
18
|
-
Taro.showToast({title: 'Hello Taro'})
|
|
18
|
+
Taro.showToast({ title: 'Hello Taro' })
|
|
19
19
|
}}
|
|
20
20
|
>
|
|
21
21
|
Show toast
|