Skip to content

Commit

Permalink
fix(*): fix style.
Browse files Browse the repository at this point in the history
  • Loading branch information
shangqunfeng committed May 14, 2024
1 parent 6a5398c commit ec530f1
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ export interface _ViewProps extends ViewProps {
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
}

function getDefaultStyle(style: Array<ViewStyle> = []) {
const mergeStyle: ViewStyle = Object.assign({}, ...style)
if (mergeStyle.display === 'flex') {
mergeStyle.flexDirection = mergeStyle.flexDirection || 'row'
mergeStyle.flexShrink = mergeStyle.flexShrink || 1
}
return mergeStyle
const DEFAULT_STYLE = {
flexDirection: 'row',
flexShrink: 1
}


const _View:React.FC<_ViewProps & React.RefAttributes<any>> = React.forwardRef((props: _ViewProps, ref: React.ForwardedRef<any>) => {
const {
style,
Expand All @@ -39,7 +34,6 @@ const _View:React.FC<_ViewProps & React.RefAttributes<any>> = React.forwardRef((
...otherProps } = props
const [isHover, setIsHover] = React.useState(false)

const mergeStyle: ViewStyle = style ? getDefaultStyle(style) : {}
const dataRef = React.useRef<{
startTimestamp: number,
startTimer?: ReturnType<typeof setTimeout>
Expand Down Expand Up @@ -106,7 +100,7 @@ const _View:React.FC<_ViewProps & React.RefAttributes<any>> = React.forwardRef((
<View
ref={ref}
{...{...otherProps, ...innerTouchable}}
style={ [ mergeStyle, isHover && hoverStyle ] }
style={ [ DEFAULT_STYLE, style, isHover && hoverStyle ] }
>
{children}
</View>
Expand Down

0 comments on commit ec530f1

Please sign in to comment.