Skip to content

Commit

Permalink
Merge branch 'feat-react-template-compiler-cr' of github.com:didi/mpx…
Browse files Browse the repository at this point in the history
… into feat-react-template-compiler-cr
  • Loading branch information
yandadaFreedom committed May 24, 2024
2 parents 48c16c1 + e52fe3c commit 67cdd41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
19 changes: 10 additions & 9 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* ✘ space
* ✘ decode
*/
import { Text, TextProps } from 'react-native'
import { Text, TextStyle, TextProps, StyleSheet } from 'react-native'
import * as React from 'react'
import { useImperativeHandle } from 'react'
// @ts-ignore
Expand All @@ -13,12 +13,12 @@ import useInnerProps from './getInnerListeners';
import useNodesRef from '../../useNodesRef' // 引入辅助函数

interface _TextProps extends TextProps {
style?: any;
children?: React.ReactNode;
selectable?: boolean;
['user-select']?: boolean;
userSelect?: boolean;
useInherit?: boolean;
style?: TextStyle
children?: React.ReactNode
selectable?: boolean
['user-select']?: boolean
userSelect?: boolean
useInherit?: boolean
}

const DEFAULT_STYLE = {
Expand All @@ -27,7 +27,7 @@ const DEFAULT_STYLE = {

const _Text: React.FC<_TextProps & React.RefAttributes<any>> = React.forwardRef((props: _TextProps, ref: React.ForwardedRef<any>):React.JSX.Element => {
const {
style,
style = [],
children,
selectable,
'user-select': userSelect,
Expand All @@ -36,6 +36,7 @@ const _Text: React.FC<_TextProps & React.RefAttributes<any>> = React.forwardRef(

const measureTimeout = React.useRef<ReturnType<typeof setTimeout> | null>(null)

const styleObj = StyleSheet.flatten(style)

const innerProps = useInnerProps(props, {}, [
'style',
Expand Down Expand Up @@ -65,7 +66,7 @@ const _Text: React.FC<_TextProps & React.RefAttributes<any>> = React.forwardRef(

return (
<Text
style={[ !useInherit && DEFAULT_STYLE, style ]}
style={{...useInherit && DEFAULT_STYLE, ...styleObj}}
ref={nodeRef}
selectable={!!selectable || !!userSelect}
{...innerProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const wrapChildren = (children, style, image) => {

const _View:React.FC<_ViewProps & React.RefAttributes<any>> = React.forwardRef((props: _ViewProps, ref: React.ForwardedRef<any>): React.JSX.Element => {
const {
style,
style = [],
children,
hoverStyle,
...otherProps } = props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const parseUrl = (cssUrl: string = '') => {
}

export const hasElementType = (element: ReactElement<any>, type: string) => {
if (!element) return false
return (element.type as FunctionComponent)?.displayName === type
}

Expand Down

0 comments on commit 67cdd41

Please sign in to comment.