Skip to content

Commit

Permalink
Merge pull request #1589 from didi/feat-rn-event-current-target
Browse files Browse the repository at this point in the history
Feat rn event current target
  • Loading branch information
hiyuki authored Aug 28, 2024
2 parents 707f497 + 4309d42 commit c40429f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions packages/webpack-plugin/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const reactConfig = {
if (match) {
return {
prefix: match[1],
eventName: match[2].replace(/^./, function (match) {
return match.toLowerCase()
}),
eventName: match[2],
modifier: match[3]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const getTouchEvent = (
...event,
type,
timeStamp: timestamp,
target: {
...(event.target || {}),
currentTarget: {
...(event.currentTarget || {}),
id: id || '',
dataset: getDataSet(props),
offsetLeft: layoutRef?.current?.offsetLeft || 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useRef, useEffect, forwardRef, ReactNode, ForwardedRef, JSX } from 'rea
import useInnerProps from './getInnerListeners'
// @ts-ignore
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
import { PERCENT_REGX } from './utils'
import { PERCENT_REGEX } from './utils'


interface _TextProps extends TextProps {
Expand All @@ -28,7 +28,7 @@ const DEFAULT_STYLE = {

const transformStyle = (styleObj: TextStyle) => {
let { lineHeight } = styleObj
if (typeof lineHeight === 'string' && PERCENT_REGX.test(lineHeight)) {
if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
lineHeight = (parseFloat(lineHeight)/100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize)
styleObj.lineHeight = lineHeight
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* ✔ hover-stay-time
*/
import { View, Text, StyleProp, TextStyle, ViewStyle, NativeSyntheticEvent, ViewProps, ImageStyle, ImageResizeMode, StyleSheet, Image, LayoutChangeEvent } from 'react-native'
import { useRef, useState, useEffect, forwardRef, ForwardedRef, ReactNode, JSX } from 'react'
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX } from 'react'
// @ts-ignore
import useInnerProps from './getInnerListeners'
// @ts-ignore
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数

import { parseUrl, TEXT_STYLE_REGEX, PERCENT_REGX, isText} from './utils'
import { parseUrl, TEXT_STYLE_REGEX, PERCENT_REGEX, isText} from './utils'


type ExtendedViewStyle = ViewStyle & {
Expand Down Expand Up @@ -79,7 +79,7 @@ const applyHandlers = (handlers: Handler[] , args: any [] ) => {

const checkNeedLayout = (style: PreImageInfo) => {
const [width, height] = style.sizeList
return (PERCENT_REGX.test(`${height}`) && width === 'auto') || (PERCENT_REGX.test(`${width}`) && height === 'auto')
return (PERCENT_REGEX.test(`${height}`) && width === 'auto') || (PERCENT_REGEX.test(`${width}`) && height === 'auto')
}

/**
Expand All @@ -89,7 +89,7 @@ const checkNeedLayout = (style: PreImageInfo) => {
* **/
function calculateSize(h: number, lh: number, ratio: number) {
let height, width
if (PERCENT_REGX.test(`${h}`)) { // auto px/rpx
if (PERCENT_REGEX.test(`${h}`)) { // auto px/rpx
if (!lh) return null
height = (parseFloat(`${h}`) / 100) * lh
width = height * ratio
Expand Down Expand Up @@ -136,8 +136,8 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
} else { // 数值类型 ImageStyle
// 数值类型设置为 stretch
(imageProps.style as ImageStyle).resizeMode = 'stretch'
newWidth = PERCENT_REGX.test(`${width}`) ? width : +width! as DimensionValue
newHeight = PERCENT_REGX.test(`${width}`) ? height : +height! as DimensionValue
newWidth = PERCENT_REGEX.test(`${width}`) ? width : +width! as DimensionValue
newHeight = PERCENT_REGEX.test(`${width}`) ? height : +height! as DimensionValue
}
// 样式合并
imageProps.style = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'

export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/

export const PERCENT_REGX = /^\s*-?\d+(\.\d+)?%\s*$/
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/

const URL_REGEX = /url\(["']?(.*?)["']?\)/

Expand Down

0 comments on commit c40429f

Please sign in to comment.