Skip to content
Closed
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
9 changes: 7 additions & 2 deletions src/packages/safearea/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -20,8 +20,13 @@ function generateRandomTextArray(count: number) {
const Demo1 = () => {
return (
<ScrollView>
<View style={{ backgroundColor: 'red' }}>
<SafeArea position="top" />
</View>
<Text>{generateRandomTextArray(900).join(' ')}</Text>
<SafeArea position="bottom" />
<View style={{ backgroundColor: 'red' }}>
<SafeArea position="bottom" />
</View>
</ScrollView>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/packages/safearea/safearea.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.nut-safe-area {
display: flex;
display: block;
width: 100%;

&-position-top {
Expand Down
17 changes: 17 additions & 0 deletions src/packages/safearea/safearea.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import React, { FC } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { TaroSafeAreaProps } from '@/types'
import { jd } from '../../utils/taro/platform'

const classPrefix = 'nut-safe-area'
export const SafeArea: FC<TaroSafeAreaProps> = (props) => {
const getSafeAreaStyle = () => {
if (jd()) {
const { screenHeight, safeArea } = Taro.getSystemInfoSync()
Comment thread
Miles-hxy marked this conversation as resolved.
if (props.position === 'top') {
return { paddingTop: safeArea?.top || 0 }
}
if (props.position === 'bottom') {
const bottom = safeArea?.bottom || screenHeight
return { paddingBottom: screenHeight - bottom }
}
}
return {}
}

return (
<View
style={getSafeAreaStyle()}
className={classNames(
classPrefix,
`${classPrefix}-position-${props.position}`
Expand Down
9 changes: 9 additions & 0 deletions src/utils/taro/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ export const harmony = () => {
getEnv().toLowerCase()
)
}

export const web = () => {
return ['web'].includes(getEnv().toLowerCase())
}

export const miniprogram = () => {
return ['mini'].includes(getEnv().toLowerCase())
}

export const weapp = () => {
return ['weapp'].includes(getEnv().toLowerCase())
}

export const jd = () => {
return ['jd'].includes(getEnv().toLowerCase())
}