Skip to content

Commit

Permalink
chore: 优化jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
lareinayanyu committed Dec 11, 2024
1 parent 3b9d81f commit 147b324
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,35 +207,10 @@ const Checkbox = forwardRef<HandlerRef<View, CheckboxProps>, CheckboxProps>(
}
}, [checked])

// return (
// <View {...innerProps}>
// <View style={defaultStyle}>
// <Icon
// type='success_no_circle'
// size={18}
// color={disabled ? '#ADADAD' : color}
// style={isChecked ? styles.iconChecked : styles.icon}
// />
// </View>
// {
// wrapChildren(
// props,
// {
// hasVarDec,
// varContext: varContextRef.current,
// textStyle,
// textProps
// }
// )
// }
// </View>
// )
return createElement(
View,
innerProps,
return createElement(View, innerProps,
createElement(
View,
{ style: defaultStyle }, // 内部 View 的样式
{ style: defaultStyle },
createElement(Icon, {
type: 'success_no_circle',
size: 18,
Expand Down
35 changes: 15 additions & 20 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* ✔ bindreset
*/
import { View } from 'react-native'
import { JSX, useRef, forwardRef, ReactNode, useMemo, useCallback } from 'react'
import { JSX, useRef, forwardRef, ReactNode, useMemo, createElement } from 'react'
import useNodesRef, { HandlerRef } from './useNodesRef'
import useInnerProps, { getCustomEvent } from './getInnerListeners'
import { FormContext } from './context'
Expand Down Expand Up @@ -102,25 +102,20 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
reset
}
}, [])
return (
<View
{...innerProps}
>
<FormContext.Provider value={contextValue}>
{
wrapChildren(
props,
{
hasVarDec,
varContext: varContextRef.current,
textStyle,
textProps
}
)
}
</FormContext.Provider>
</View>
)

return createElement(View, innerProps, createElement(
FormContext.Provider,
{ value: contextValue },
wrapChildren(
props,
{
hasVarDec,
varContext: varContextRef.current,
textStyle,
textProps
}
)
))
})

_Form.displayName = 'MpxForm'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ✔ size
* ✔ color
*/
import { JSX, forwardRef, useRef } from 'react'
import { JSX, forwardRef, useRef, createElement } from 'react'
import { Text, TextStyle, Image } from 'react-native'
import useInnerProps from './getInnerListeners'
import useNodesRef, { HandlerRef } from './useNodesRef'
Expand Down Expand Up @@ -93,7 +93,7 @@ const Icon = forwardRef<HandlerRef<Text, IconProps>, IconProps>(
}
)

return <Image {...innerProps} />
return createElement(Image, innerProps)
}
)

Expand Down
56 changes: 26 additions & 30 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* ✔ bindtap
* ✔ DEFAULT_SIZE
*/
import { useEffect, useMemo, useState, useRef, forwardRef } from 'react'
import { useEffect, useMemo, useState, useRef, forwardRef, createElement } from 'react'
import {
Image as RNImage,
View,
Expand Down Expand Up @@ -359,35 +359,31 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
}
)

return (
<View {...innerProps}>
{
isSvg
? <SvgCssUri
uri={src}
onLayout={onSvgLoad}
onError={binderror && onSvgError}
style={extendObject(
{ transformOrigin: 'top left' },
modeStyle
)}
/>
: <RNImage
source={{ uri: src }}
resizeMode={resizeMode}
onLoad={bindload && onImageLoad}
onError={binderror && onImageError}
style={extendObject(
{
transformOrigin: 'top left',
width: isCropMode ? imageWidth : '100%',
height: isCropMode ? imageHeight : '100%'
},
isCropMode ? modeStyle : {}
)}
/>
}
</View>
return createElement(View, innerProps,
isSvg
? createElement(SvgCssUri, {
uri: src,
onLayout: onSvgLoad,
onError: binderror && onSvgError,
style: extendObject(
{ transformOrigin: 'top left' },
modeStyle
)
})
: createElement(RNImage, {
source: { uri: src },
resizeMode: resizeMode,
onLoad: bindload && onImageLoad,
onError: binderror && onImageError,
style: extendObject(
{
transformOrigin: 'top left',
width: isCropMode ? imageWidth : '100%',
height: isCropMode ? imageHeight : '100%'
},
isCropMode ? modeStyle : {}
)
})
)
})

Expand Down
54 changes: 23 additions & 31 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* ✘ bind:keyboardcompositionend
* ✘ bind:onkeyboardheightchange
*/
import { JSX, forwardRef, useMemo, useRef, useState, useContext, useEffect } from 'react'
import { JSX, forwardRef, useMemo, useRef, useState, useContext, useEffect, createElement } from 'react'
import {
KeyboardTypeOptions,
Platform,
Expand Down Expand Up @@ -405,62 +405,54 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
{
ref: nodeRef,
style: extendObject({}, normalStyle, layoutStyle),
allowFontScaling
allowFontScaling,
keyboardType: keyboardType,
secureTextEntry: !!password,
defaultValue: defaultValue,
value: inputValue,
maxLength: maxlength === -1 ? undefined : maxlength,
editable: !disabled,
autoFocus: !!autoFocus || !!focus,
returnKeyType: confirmType,
selection: selection,
selectionColor: cursorColor,
blurOnSubmit: !multiline && !confirmHold,
underlineColorAndroid: 'rgba(0,0,0,0)',
textAlignVertical: textAlignVertical,
placeholderTextColor: placeholderTextColor,
multiline: !!multiline
},
layoutProps,
{
onFocus: bindfocus && onInputFocus,
onBlur: bindblur && onInputBlur,
onKeyPress: bindconfirm && onKeyPress,
onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
onSelectionChange: bindselectionchange && onSelectionChange
onSelectionChange: bindselectionchange && onSelectionChange,
onTextInput: onTextInput,
onChange: onChange,
onContentSizeChange: onContentSizeChange
}
),
[
'type',
'keyboardType',
'password',
'placeholder-style',
'disabled',
'maxlength',
'auto-focus',
'focus',
'confirm-type',
'confirm-hold',
'cursor',
'cursor-color',
'selection-start',
'selection-end',
'multiline'
'selection-end'
],
{
layoutRef
}
)

return (
<TextInput
{...innerProps}
keyboardType={keyboardType as KeyboardTypeOptions}
secureTextEntry={!!password}
defaultValue={defaultValue}
value={inputValue}
maxLength={maxlength === -1 ? undefined : maxlength}
editable={!disabled}
autoFocus={!!autoFocus || !!focus}
returnKeyType={confirmType}
selection={selection}
selectionColor={cursorColor}
blurOnSubmit={!multiline && !confirmHold}
underlineColorAndroid="rgba(0,0,0,0)"
textAlignVertical={textAlignVertical}
placeholderTextColor={placeholderTextColor}
multiline={!!multiline}
onTextInput={onTextInput}
onChange={onChange}
onContentSizeChange={onContentSizeChange}
/>
)
return createElement(TextInput, innerProps)
})

Input.displayName = 'MpxInput'
Expand Down
26 changes: 12 additions & 14 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-label.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* ✘ for
*/
import { JSX, useRef, forwardRef, ReactNode, useCallback } from 'react'
import { JSX, useRef, forwardRef, ReactNode, useCallback, createElement } from 'react'
import { View, ViewStyle, NativeSyntheticEvent } from 'react-native'
import { noop, warn } from '@mpxjs/utils'
import useInnerProps, { getCustomEvent } from './getInnerListeners'
Expand Down Expand Up @@ -92,21 +92,19 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
}
)

return <View {...innerProps}>
<LabelContext.Provider value={contextRef}>
return createElement(View, innerProps, createElement(
LabelContext.Provider,
{ value: contextRef },
wrapChildren(
props,
{
wrapChildren(
props,
{
hasVarDec,
varContext: varContextRef.current,
textStyle,
textProps
}
)
hasVarDec,
varContext: varContextRef.current,
textStyle,
textProps
}
</LabelContext.Provider>
</View>
)
))
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { View } from 'react-native'
import { JSX, forwardRef, ReactNode, useRef, useMemo } from 'react'
import { JSX, forwardRef, ReactNode, useRef, useMemo, createElement } from 'react'
import useNodesRef, { HandlerRef } from './useNodesRef'
import useInnerProps from './getInnerListeners'
import { MovableAreaContext } from './context'
Expand Down Expand Up @@ -51,23 +51,17 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
ref: movableViewRef
}, layoutProps), [], { layoutRef })

return (
<MovableAreaContext.Provider value={contextValue}>
<View
{...innerProps}
>
return createElement(MovableAreaContext.Provider, { value: contextValue }, createElement(
View,
innerProps,
wrapChildren(
props,
{
wrapChildren(
props,
{
hasVarDec,
varContext: varContextRef.current
}
)
hasVarDec,
varContext: varContextRef.current
}
</View>
</MovableAreaContext.Provider>
)
)
))
})

_MovableArea.displayName = 'MpxMovableArea'
Expand Down
Loading

0 comments on commit 147b324

Please sign in to comment.