Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat rn comps pref #1807

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
const { Provider, useSafeAreaInsets, GestureHandlerRootView } = global.__navigationHelper
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
const Page = ({ navigation, route }) => {
const [enabled, setEnabled] = useState(true)
const [enabled, setEnabled] = useState(false)
const currentPageId = useMemo(() => ++pageId, [])
const intersectionObservers = useRef({})
usePageStatus(navigation, currentPageId)
Expand Down
66 changes: 41 additions & 25 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,32 +403,48 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
}
)

return createElement(View, innerProps,
isSvg
? createElement(SvgCssUri, {
uri: src,
onLayout: onSvgLoad,
onError: binderror && onSvgError,
style: extendObject(
{ transformOrigin: 'top left' },
modeStyle
)
})
: loaded && renderImage({
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 : {}
)
}, enableFastImage)
const createBaseImage = (innerProps = {}) => {
return renderImage(
extendObject(
{
source: { uri: src },
resizeMode: resizeMode,
onLoad: bindload && onImageLoad,
onError: binderror && onImageError,
style: extendObject(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个样式会被innerProps中的style覆盖

{
transformOrigin: 'top left',
width: isCropMode ? imageWidth : '100%',
height: isCropMode ? imageHeight : '100%'
},
isCropMode ? modeStyle : {}
)
},
innerProps
),
enableFastImage
)
}

const SvgImage = createElement(
View,
innerProps,
createElement(SvgCssUri, {
uri: src,
onLayout: onSvgLoad,
onError: binderror && onSvgError,
style: extendObject(
{ transformOrigin: 'top left' },
modeStyle
)
})
)

const BaseImage = createBaseImage(innerProps)

const LayoutImage = createElement(View, innerProps, loaded && createBaseImage())

return isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage
})

Image.displayName = 'mpx-image'
Expand Down
18 changes: 10 additions & 8 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
'parent-font-size': parentFontSize,
'parent-width': parentWidth,
'parent-height': parentHeight,
'adjust-position': adjustPosition = true,
'adjust-position': adjustPosition = false,
bindinput,
bindfocus,
bindblur,
Expand Down Expand Up @@ -182,6 +182,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps

const [inputValue, setInputValue] = useState(defaultValue)
const [contentHeight, setContentHeight] = useState(0)
const [selection, setSelection] = useState({ start: -1, end: -1 })

const styleObj = extendObject(
{ padding: 0, backgroundColor: '#fff' },
Expand Down Expand Up @@ -211,11 +212,11 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}
}, [value])

const selection = useMemo(() => {
if (selectionStart >= 0 && selectionEnd >= 0) {
return { start: selectionStart, end: selectionEnd }
} else if (typeof cursor === 'number') {
return { start: cursor, end: cursor }
useEffect(() => {
if (typeof cursor === 'number') {
setSelection({ start: cursor, end: cursor })
} else if (selectionStart >= 0 && selectionEnd >= 0 && selectionStart !== selectionEnd) {
setSelection({ start: selectionStart, end: selectionEnd })
}
}, [cursor, selectionStart, selectionEnd])

Expand Down Expand Up @@ -320,7 +321,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}

const onSelectionChange = (evt: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
bindselectionchange!(
setSelection(evt.nativeEvent.selection)
bindselectionchange && bindselectionchange(
getCustomEvent(
'selectionchange',
evt,
Expand Down Expand Up @@ -428,7 +430,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
onBlur: bindblur && onInputBlur,
onKeyPress: bindconfirm && onKeyPress,
onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
onSelectionChange: bindselectionchange && onSelectionChange,
onSelectionChange: onSelectionChange,
onTextInput: onTextInput,
onChange: onChange,
onContentSizeChange: onContentSizeChange
Expand Down
Loading