From bcc81b7c570460072faa609d64f6a55000f1c621 Mon Sep 17 00:00:00 2001 From: "Alex.hxy" <1872591453@qq.com> Date: Thu, 17 Apr 2025 10:39:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(safearea):=20=E5=9C=A8=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8E=AF=E5=A2=83=E5=AE=89=E5=85=A8=E5=8C=BA?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E6=9C=AA=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/safearea/demos/taro/demo1.tsx | 9 +++++++-- src/packages/safearea/safearea.scss | 2 +- src/packages/safearea/safearea.taro.tsx | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/packages/safearea/demos/taro/demo1.tsx b/src/packages/safearea/demos/taro/demo1.tsx index 3302843844..d0492c2968 100644 --- a/src/packages/safearea/demos/taro/demo1.tsx +++ b/src/packages/safearea/demos/taro/demo1.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { ScrollView, Text } from '@tarojs/components' +import { ScrollView, Text, View } from '@tarojs/components' import { SafeArea } from '@nutui/nutui-react-taro' function generateRandomTextArray(count: number) { @@ -20,8 +20,13 @@ function generateRandomTextArray(count: number) { const Demo1 = () => { return ( + + + {generateRandomTextArray(900).join(' ')} - + + + ) } diff --git a/src/packages/safearea/safearea.scss b/src/packages/safearea/safearea.scss index 62b8722282..bbed5d12fa 100644 --- a/src/packages/safearea/safearea.scss +++ b/src/packages/safearea/safearea.scss @@ -1,5 +1,5 @@ .nut-safe-area { - display: flex; + display: block; width: 100%; &-position-top { diff --git a/src/packages/safearea/safearea.taro.tsx b/src/packages/safearea/safearea.taro.tsx index 714cb7a889..57c9b34c39 100644 --- a/src/packages/safearea/safearea.taro.tsx +++ b/src/packages/safearea/safearea.taro.tsx @@ -1,12 +1,28 @@ import React, { FC } from 'react' import classNames from 'classnames' import { View } from '@tarojs/components' +import Taro from '@tarojs/taro' import { TaroSafeAreaProps } from '@/types' const classPrefix = 'nut-safe-area' export const SafeArea: FC = (props) => { + const getSafeAreaStyle = () => { + if (['WEAPP', 'JD'].includes(Taro.getEnv())) { + const { screenHeight, safeArea } = Taro.getSystemInfoSync() + if (props.position === 'top') { + return { paddingTop: `${safeArea?.top || 0}px` } + } + if (props.position === 'bottom') { + const bottom = safeArea?.bottom || screenHeight + return { paddingBottom: `${screenHeight - bottom}px` } + } + } + return {} + } + return ( Date: Thu, 17 Apr 2025 14:21:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(safearea):=20=E5=9C=A8=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8E=AF=E5=A2=83=E5=AE=89=E5=85=A8=E5=8C=BA?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E6=9C=AA=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/safearea/safearea.taro.tsx | 7 ++++--- src/utils/taro/platform.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/packages/safearea/safearea.taro.tsx b/src/packages/safearea/safearea.taro.tsx index 57c9b34c39..3669e7437b 100644 --- a/src/packages/safearea/safearea.taro.tsx +++ b/src/packages/safearea/safearea.taro.tsx @@ -3,18 +3,19 @@ import classNames from 'classnames' import { View } from '@tarojs/components' import Taro from '@tarojs/taro' import { TaroSafeAreaProps } from '@/types' +import { jd, weapp } from '../nutui.react.build.taro' const classPrefix = 'nut-safe-area' export const SafeArea: FC = (props) => { const getSafeAreaStyle = () => { - if (['WEAPP', 'JD'].includes(Taro.getEnv())) { + if (weapp() || jd()) { const { screenHeight, safeArea } = Taro.getSystemInfoSync() if (props.position === 'top') { - return { paddingTop: `${safeArea?.top || 0}px` } + return { paddingTop: safeArea?.top || 0 } } if (props.position === 'bottom') { const bottom = safeArea?.bottom || screenHeight - return { paddingBottom: `${screenHeight - bottom}px` } + return { paddingBottom: screenHeight - bottom } } } return {} diff --git a/src/utils/taro/platform.ts b/src/utils/taro/platform.ts index 02ff3e9072..475a759d33 100644 --- a/src/utils/taro/platform.ts +++ b/src/utils/taro/platform.ts @@ -5,6 +5,7 @@ export const harmony = () => { getEnv().toLowerCase() ) } + export const web = () => { return ['web'].includes(getEnv().toLowerCase()) } @@ -12,3 +13,11 @@ export const web = () => { export const miniprogram = () => { return ['mini'].includes(getEnv().toLowerCase()) } + +export const weapp = () => { + return ['weapp'].includes(getEnv().toLowerCase()) +} + +export const jd = () => { + return ['jd'].includes(getEnv().toLowerCase()) +} From 2e841fe732aca8a21fa948ff348154de41933695 Mon Sep 17 00:00:00 2001 From: "Alex.hxy" <1872591453@qq.com> Date: Fri, 18 Apr 2025 16:07:06 +0800 Subject: [PATCH 3/4] chore: delete weapp() --- src/packages/safearea/safearea.taro.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/packages/safearea/safearea.taro.tsx b/src/packages/safearea/safearea.taro.tsx index 3669e7437b..4f9da53a31 100644 --- a/src/packages/safearea/safearea.taro.tsx +++ b/src/packages/safearea/safearea.taro.tsx @@ -3,12 +3,12 @@ import classNames from 'classnames' import { View } from '@tarojs/components' import Taro from '@tarojs/taro' import { TaroSafeAreaProps } from '@/types' -import { jd, weapp } from '../nutui.react.build.taro' +import { jd } from '../nutui.react.build.taro' const classPrefix = 'nut-safe-area' export const SafeArea: FC = (props) => { const getSafeAreaStyle = () => { - if (weapp() || jd()) { + if (jd()) { const { screenHeight, safeArea } = Taro.getSystemInfoSync() if (props.position === 'top') { return { paddingTop: safeArea?.top || 0 } From 57877236413d8a8c36f092454101128aeaa36cc4 Mon Sep 17 00:00:00 2001 From: "Alex.hxy" <1872591453@qq.com> Date: Fri, 18 Apr 2025 16:24:13 +0800 Subject: [PATCH 4/4] chore: platform jd import --- src/packages/safearea/safearea.taro.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/safearea/safearea.taro.tsx b/src/packages/safearea/safearea.taro.tsx index 4f9da53a31..1082b27b09 100644 --- a/src/packages/safearea/safearea.taro.tsx +++ b/src/packages/safearea/safearea.taro.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames' import { View } from '@tarojs/components' import Taro from '@tarojs/taro' import { TaroSafeAreaProps } from '@/types' -import { jd } from '../nutui.react.build.taro' +import { jd } from '../../utils/taro/platform' const classPrefix = 'nut-safe-area' export const SafeArea: FC = (props) => {