Skip to content

Commit

Permalink
fix: 鸿蒙适配
Browse files Browse the repository at this point in the history
  • Loading branch information
irisSong committed Sep 26, 2024
1 parent d906bc9 commit 9a61a86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/packages/badge/badge.harmony.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
padding: 0;
}
.nut-badge-content {
/* #ifdef harmony */
top: 0;
/* #endif */
/* #ifndef rn harmony */
top: initial;
/* #ifndef rn */
transform: translateX(100%);
/* #endif */
}
Expand Down
6 changes: 1 addition & 5 deletions src/packages/badge/badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@
}

&-content {
/* #ifdef harmony */
top: 0;
/* #endif */
/* #ifndef rn harmony */
top: initial;
/* #ifndef rn */
transform: $badge-content-transform;
/* #endif */
}
Expand Down
23 changes: 10 additions & 13 deletions src/packages/badge/badge.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { useRtl } from '@/packages/configprovider/index.taro'
import pxTransform from '@/utils/px-transform'
import { getRectByTaro } from '@/utils/get-rect-by-taro'
import { harmonyAndRn } from '@/utils/platform-taro'
import { harmony, rn } from '@/utils/platform-taro'

export type BadgeFill = 'solid' | 'outline'
export interface BadgeProps extends BasicComponent {
Expand Down Expand Up @@ -53,7 +53,6 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
}
const classPrefix = 'nut-badge'
const classes = classNames(classPrefix, className)
const isHarmonyAndRn = harmonyAndRn()
const badgeRef = useRef(null)
const [contentStyle, setContentStyle] = useState({})

Expand Down Expand Up @@ -93,19 +92,17 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
const getPositionStyle = async () => {
const style: CSSProperties = {}
style.top = pxTransform(Number(-top) || 0)
if (isHarmonyAndRn) {
try {
const reacts = await getRectByTaro(badgeRef.current)
style.left =
reacts?.width && reacts?.width > Number(right)
? pxTransform(reacts.width - Number(right))
: 0
} catch (error) {
console.log(error)
}
if (rn()) {
const reacts = await getRectByTaro(badgeRef.current)
style.left =
reacts?.width && reacts?.width > Number(right)
? pxTransform(reacts.width - Number(right))
: 0
} else {
const dir = rtl ? 'left' : 'right'
style[dir] = `${Number(right) || parseFloat(String(right)) || 0}px`
style[dir] = harmony()
? pxTransform(Number(right))
: `${Number(right) || parseFloat(String(right)) || 0}px`
}
setContentStyle(style)
}
Expand Down

0 comments on commit 9a61a86

Please sign in to comment.