Skip to content

Commit

Permalink
fix: Android config
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshunnn committed Dec 23, 2024
1 parent 8395ee1 commit 6636443
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react'
import { LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, Platform, SafeAreaView, ScrollView, StyleSheet, View } from 'react-native'
import { LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, SafeAreaView, ScrollView, StyleSheet, View } from 'react-native'
import Reanimated, { AnimatedRef, useAnimatedRef, useScrollViewOffset } from 'react-native-reanimated'
import { vibrateShort } from '@mpxjs/api-proxy'
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious } from './utils'
import { useTransformStyle, splitStyle, splitProps, useLayout, usePrevious, isAndroid } from './utils'
import useNodesRef, { HandlerRef } from './useNodesRef'
import PickerOverlay from './pickerViewOverlay'
import PickerMask from './pickerViewMask'
Expand Down Expand Up @@ -87,8 +86,6 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
nodeRef: scrollViewRef
})

console.log('[mpx-picker-view-column], render ---> columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'columnData=', columnData.length)

// const initialOffset = useMemo(() => ({
// x: 0,
// y: itemRawH * initialIndex
Expand All @@ -114,6 +111,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
}, [itemRawH, maxIndex])

useEffect(() => {
// console.log('[mpx-picker-view-column], useEffect000 --->', 'columnIndex=', columnIndex, 'initialIndex=', initialIndex, 'prevIndex=', prevIndex, 'activeIndex=', activeIndex.current, 'maxIndex=', maxIndex, 'prevMaxIndex=', prevMaxIndex)
if (
!scrollViewRef.current ||
!itemRawH ||
Expand All @@ -132,7 +130,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
y: itemRawH * initialIndex,
animated: false
})
}, 0)
}, isAndroid ? 200 : 0)
activeIndex.current = initialIndex
}, [itemRawH, initialIndex])

Expand All @@ -146,6 +144,10 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
}

const onScrollViewLayout = (e: LayoutChangeEvent) => {
if (isAndroid) {
return
}
// RN iOS bug: https://github.com/facebook/react-native/issues/36135
const { width } = e.nativeEvent.layout
const widthInt = Math.ceil(width)
if (widthInt !== scrollViewWidth) {
Expand Down Expand Up @@ -205,7 +207,12 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
}

const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
if (Platform.OS === 'android') {
if (isAndroid) {
return
}
// 全局注册的震动触感 hook
const pickerVibrate = global.__mpx.config.rnConfig.pickerVibrate
if (typeof pickerVibrate !== 'function') {
return
}
const { y } = e.nativeEvent.contentOffset
Expand All @@ -218,7 +225,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
index: currentId,
y: currentId * itemRawH
}
vibrateShort({ type: 'selection' })
// vibrateShort({ type: 'selection' })
pickerVibrate()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
import { LayoutChangeEvent, TextStyle, ImageProps, Image, Platform } from 'react-native'
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn, getFocusedNavigation } from '@mpxjs/utils'
import { VarContext } from './context'
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
Expand All @@ -18,6 +18,9 @@ export const HIDDEN_STYLE = {
opacity: 0
}

export const isIOS = Platform.OS === 'ios'
export const isAndroid = Platform.OS === 'android'

const varDecRegExp = /^--.*/
const varUseRegExp = /var\(/
const calcUseRegExp = /calc\(/
Expand Down

0 comments on commit 6636443

Please sign in to comment.