Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/vantui/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Taro, {
getSystemInfoSync as TaroGetSystemInfoSync,
getWindowInfo as TaroGetWindowInfo,
createSelectorQuery,
} from '@tarojs/taro'
import * as raf from 'raf'
Expand All @@ -25,6 +26,13 @@ export function getSystemInfoSync() {
return systemInfo
}

let windowInfo: any
export function getWindowInfo() {
windowInfo =
process.env.TARO_ENV === 'weapp' ? TaroGetWindowInfo() : getSystemInfoSync()
return windowInfo
}

let menuInfo: any
export function getMenuButtonBoundingClientRect() {
if (menuInfo == null) {
Expand Down
13 changes: 4 additions & 9 deletions packages/vantui/src/common/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Taro, {
getSystemInfoSync as TaroGetSystemInfoSync,
canIUse,
getAppBaseInfo as TaroGetAppBaseInfo,
} from '@tarojs/taro'
import { getSystemInfoSync } from './utils'
function compareVersion(v1: any, v2: any) {
v1 = v1.split('.')
v2 = v2.split('.')
Expand All @@ -24,15 +25,9 @@ function compareVersion(v1: any, v2: any) {
}
return 0
}
let systemInfo: any
function getSystemInfoSync() {
if (systemInfo == null) {
systemInfo = TaroGetSystemInfoSync()
}
return systemInfo
}
function gte(version: any) {
const system = getSystemInfoSync()
const system =
process.env.TARO_ENV === 'weapp' ? TaroGetAppBaseInfo : getSystemInfoSync()
return compareVersion(system.SDKVersion || system.version, version) >= 0
}
export function canIUseModel() {
Expand Down
4 changes: 2 additions & 2 deletions packages/vantui/src/dropdown-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
memo,
} from 'react'
import { nextTick, usePageScroll } from '@tarojs/taro'
import { getSystemInfoSync, requestAnimationFrame } from '../common/utils'
import { getWindowInfo, requestAnimationFrame } from '../common/utils'
import {
DropdownItemProps,
IDropdownItemInstance,
Expand Down Expand Up @@ -86,7 +86,7 @@ function Index(
}

if (parentInstance.direction === 'down') {
const winHeight = getSystemInfoSync().windowHeight
const winHeight = getWindowInfo().windowHeight
const bottom = winHeight - rect.top
wrapperStyle.bottom = -rect.height + 'PX'
wrapperStyle.height = bottom + 'PX'
Expand Down
4 changes: 2 additions & 2 deletions packages/vantui/src/image-cropper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Canvas, Image, View } from '@tarojs/components'
import { useEffect, useMemo, useRef, useState } from 'react'
import {
getSystemInfoSync,
getWindowInfo,
showLoading,
hideLoading,
getImageInfo,
Expand All @@ -22,7 +22,7 @@ const pageRects = {
windowHeight: 0,
pixelRatio: 1,
}
const res = getSystemInfoSync()
const res = getWindowInfo()
const { windowWidth, windowHeight, pixelRatio } = res
pageRects.windowWidth = windowWidth
pageRects.windowHeight = windowHeight
Expand Down
7 changes: 2 additions & 5 deletions packages/vantui/src/mini-nav-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { useState, useEffect, useCallback, useMemo } from 'react'
import { View } from '@tarojs/components'
import * as utils from '../wxs/utils'
import { Icon } from '../icon'
import {
getSystemInfoSync,
getMenuButtonBoundingClientRect,
} from '../common/utils'
import { getWindowInfo, getMenuButtonBoundingClientRect } from '../common/utils'
import { MiniNavBarProps } from '../../types/mini-nav-bar'
import * as computed from './wxs'

Expand Down Expand Up @@ -66,7 +63,7 @@ export function MiniNavBar(props: MiniNavBarProps) {
}, [homeUrl])

useEffect(() => {
const sysInfo = getSystemInfoSync()
const sysInfo = getWindowInfo()
const menuInfo = getMenuButtonBoundingClientRect()
if (sysInfo && menuInfo) {
setState({
Expand Down
4 changes: 2 additions & 2 deletions packages/vantui/src/nav-bar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo, useState } from 'react'
import { View } from '@tarojs/components'
import * as utils from '../wxs/utils'
import { getSystemInfoSync } from '../common/utils'
import { getWindowInfo } from '../common/utils'
import { NavBarProps } from '../../types/nav-bar'
import { Icon } from '../icon'
import { get } from '../default-props'
Expand Down Expand Up @@ -33,7 +33,7 @@ export function NavBar(props: NavBarProps) {
}

const statusBarHeight = useMemo(() => {
const { statusBarHeight: _statusBarHeight } = getSystemInfoSync()
const { statusBarHeight: _statusBarHeight } = getWindowInfo()
if (isNaN(_statusBarHeight)) {
return 22
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vantui/src/notify/notify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nextTick } from '@tarojs/taro'
import * as utils from '../wxs/utils'
import { NotifyProps } from '../../types/notify'
import VanTransition from '../transition/index'
import { getSystemInfoSync } from '../common/utils'
import { getWindowInfo } from '../common/utils'
import { get } from '../default-props'
import * as computed from './wxs'

Expand Down Expand Up @@ -68,7 +68,7 @@ export function Notify(props: NotifyProps) {

useEffect(() => {
nextTick(() => {
const { statusBarHeight } = getSystemInfoSync()
const { statusBarHeight } = getWindowInfo()
setState((state) => {
return {
...state,
Expand Down
5 changes: 3 additions & 2 deletions packages/vantui/src/water-mark/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createSelectorQuery, getSystemInfo } from '@tarojs/taro'
import { createSelectorQuery } from '@tarojs/taro'
import { getWindowInfo } from '../common/utils'

export function getCanvas(compIndex) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -35,7 +36,7 @@ export function getWaterData({
}): Promise<string> {
return new Promise(async (resolve) => {
const ctx = canvas.getContext('2d')
const ratio = (await getSystemInfo()).pixelRatio
const ratio = getWindowInfo().pixelRatio
const canvasWidth = `${(gapX + width) * ratio}px`
const canvasHeight = `${(gapY + height) * ratio}px`

Expand Down
Loading