Skip to content

Commit

Permalink
Merge branch 'master' into feat-supplement-1202
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki authored Dec 19, 2024
2 parents 7386e9c + 0022742 commit a2ca855
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 113 deletions.
6 changes: 6 additions & 0 deletions packages/api-proxy/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export const createVideoContext: WechatMiniprogram.Wx['createVideoContext']
export const onWindowResize: WechatMiniprogram.Wx['onWindowResize']
export const offWindowResize: WechatMiniprogram.Wx['offWindowResize']
export const createAnimation: WechatMiniprogram.Wx['createAnimation']
export const vibrateShort: WechatMiniprogram.Wx['vibrateShort']
export const vibrateLong: WechatMiniprogram.Wx['vibrateLong']
export const getExtConfig: WechatMiniprogram.Wx['getExtConfig']
export const getExtConfigSync: WechatMiniprogram.Wx['getExtConfigSync']
export const openLocation: WechatMiniprogram.Wx['openLocation']
export const chooseLocation: WechatMiniprogram.Wx['chooseLocation']

declare const install: (...args: any) => any

Expand Down
148 changes: 67 additions & 81 deletions packages/api-proxy/src/platform/api/action-sheet/rnActionSheet.jsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import { View, TouchableHighlight, Text, StyleSheet, Button, Animated } from 'react-native'
import { View, TouchableHighlight, Text, StyleSheet, TouchableOpacity } from 'react-native'
import { successHandle, failHandle } from '../../../common/js'
import { Portal } from '@ant-design/react-native'
import { getWindowInfo } from '../system/rnSystem'
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming
} from 'react-native-reanimated'
function showActionSheet (options = {}) {
const { alertText, itemList = [], itemColor = '#000000', success, fail, complete } = options
let actionSheetKey
const slideAnim = new Animated.Value(500)
const slideIn = () => {
// Will change fadeAnim value to 1 in 5 seconds
Animated.timing(slideAnim, {
toValue: 0,
duration: 200,
useNativeDriver: true,
}).start()
}
const slideOut = () => {
// Will change fadeAnim value to 1 in 5 seconds
Animated.timing(slideAnim, {
toValue: 500,
duration: 200,
useNativeDriver: true,
}).start(() => {
})
}
if (itemList.length === 0 || itemList.length > 6) {
const result = {
errMsg: 'showActionSheet:fail parameter error: itemList should not be large than 6'
}
if (itemList.length === 0) {
result.errno = 1001
result.errMsg = 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item;'
}
failHandle(result, fail, complete)
return
}
const windowInfo = getWindowInfo()
const bottom = windowInfo.screenHeight - windowInfo.safeArea.bottom
let actionSheetKey = null
const styles = StyleSheet.create({
actionActionMask: {
left: 0,
Expand All @@ -44,16 +23,14 @@ function showActionSheet (options = {}) {
zIndex: 1000
},
actionSheetContent: {
left: 0,
right: 0,
position: 'absolute',
bottom: 0,
backgroundColor: '#ffffff',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
transform: [{
translateY: -500
}]
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
paddingBottom: bottom
},
itemStyle: {
paddingTop: 15,
Expand All @@ -73,53 +50,62 @@ function showActionSheet (options = {}) {
paddingBottom: 10
}
})
const remove = function () {
if (actionSheetKey) {
slideOut()
setTimeout(() => {
Portal.remove(actionSheetKey)
actionSheetKey = null
}, 200)
function ActionSheet () {
const offset = useSharedValue(1000);

const animatedStyles = useAnimatedStyle(() => ({
transform: [{ translateY: offset.value }],
}))

const slideOut = () => {
// Will change fadeAnim value to 1 in 5 seconds
offset.value = withTiming(1000)
}
}
const selectAction = function (index) {
const result = {
errMsg: 'showActionSheet:ok',
tapIndex: index

offset.value = withTiming(0)

const selectAction = function (index) {
const result = {
errMsg: 'showActionSheet:ok',
tapIndex: index
}
successHandle(result, success, complete)
remove()
}
successHandle(result, success, complete)
remove()
}
const cancelAction = function () {
const result = {
errMsg: 'showActionSheet:fail cancel'

const remove = function () {
if (actionSheetKey) {
slideOut()
setTimeout(() => {
Portal.remove(actionSheetKey)
actionSheetKey = null
}, 200)
}
}
failHandle(result, fail, complete)
remove()
}
let alertTextList = []
if (alertText) {
alertTextList = [alertText]

const cancelAction = function () {
const result = {
errMsg: 'showActionSheet:fail cancel'
}
failHandle(result, fail, complete)
remove()
}
return (
<TouchableHighlight underlayColor="rgba(0,0,0,0.6)" onPress={cancelAction} style={styles.actionActionMask}>
<Animated.View style={[styles.actionSheetContent, animatedStyles]} >
{ alertText ? <View style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{alertText}</Text></View> : null }
{ itemList.map((item, index) => <TouchableHighlight key={index} underlayColor="#ececec" onPress={() => selectAction(index)} style={ [styles.itemStyle, itemList.length -1 === index ? {
borderBottomWidth: 6,
borderBottomStyle: 'solid',
borderBottomColor: '#f7f7f7'
} : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></TouchableHighlight>) }
<View style={styles.buttonStyle}><TouchableOpacity onPress={cancelAction}><Text style={{ color: "#000000", width: "100%", textAlign: "center" }}>取消</Text></TouchableOpacity></View>
</Animated.View>
</TouchableHighlight>
)
}
const ActionSheetView = <TouchableHighlight underlayColor="rgba(0,0,0,0.6)" onPress={cancelAction} style={styles.actionActionMask}>
<Animated.View
style={[
styles.actionSheetContent,
{
transform: [{translateY: slideAnim}]
}
]}>
{ alertTextList.map((item, index) => <View key={index} style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{item}</Text></View>) }
{ itemList.map((item, index) => <TouchableHighlight key={index} underlayColor="#ececec" onPress={() => selectAction(index)} style={ [styles.itemStyle, itemList.length -1 === index ? {
borderBottomWidth: 6,
borderBottomStyle: 'solid',
borderBottomColor: '#f7f7f7'
} : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></TouchableHighlight>) }
<View style={styles.buttonStyle}><Button color={'#000000'} title={'取消'} onPress={cancelAction}></Button></View>
</Animated.View>
</TouchableHighlight>
actionSheetKey = Portal.add(ActionSheetView)
slideIn()

actionSheetKey = Portal.add(<ActionSheet/>)
}

export {
Expand Down
15 changes: 7 additions & 8 deletions packages/api-proxy/src/platform/api/modal/rnModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const showModal = function (options = {}) {
fail,
complete
} = options
const modalWidth = width - 60
const modalWidth = width * 0.8
const styles = StyleSheet.create({
modalTask: {
left: 0,
Expand Down Expand Up @@ -53,7 +53,8 @@ const showModal = function (options = {}) {
lineHeight: 26,
color: '#808080',
paddingLeft: 20,
paddingRight: 20
paddingRight: 20,
textAlign: 'center'
},
modalBtnBox: {
borderTopWidth: StyleSheet.hairlineWidth,
Expand All @@ -67,8 +68,8 @@ const showModal = function (options = {}) {
modalBtn: {
flex: 1,
textAlign: 'center',
paddingTop: 10,
paddingBottom: 10,
paddingTop: width * 0.04,
paddingBottom: width * 0.04,
},
modalButton: {
width: '100%',
Expand All @@ -88,9 +89,8 @@ const showModal = function (options = {}) {
let editableContent = []
let modalButton = [{
text: confirmText,
confirmColor,
type: 'confirm',
color: 'rgb(87, 107, 149)'
color: confirmColor
}]
let contentText = content
const onChangeText = function (text) {
Expand Down Expand Up @@ -128,10 +128,9 @@ const showModal = function (options = {}) {
if (showCancel) {
modalButton.unshift({
text: cancelText,
cancelColor,
type: 'cancel',
style: styles.cancelStyle,
color: '#000000'
color: cancelColor
})
}
ModalView = <View style={styles.modalTask}>
Expand Down
4 changes: 2 additions & 2 deletions packages/api-proxy/src/platform/api/system/rnSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const getWindowInfo = function () {
const insets = Object.assign(initialWindowMetricsInset, navigationInsets)
let safeArea = {}
const { top = 0, bottom = 0, left = 0, right = 0 } = insets
const screenHeight = dimensionsScreen.height
const screenWidth = dimensionsScreen.width
const screenHeight = __mpx_mode__ === 'ios' ? dimensionsScreen.height : dimensionsScreen.height - bottom // 解决安卓开启屏幕内三建导航安卓把安全区计算进去后产生的影响
const screenWidth = __mpx_mode__ === 'ios' ? dimensionsScreen.width : dimensionsScreen.width - right
const layout = navigation.layout || {}
const layoutHeight = layout.height || 0
const layoutWidth = layout.width || 0
Expand Down
4 changes: 2 additions & 2 deletions packages/api-proxy/src/platform/api/toast/rnToast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const styles = StyleSheet.create({
backgroundColor: 'rgba(20, 20, 20, 0.7)',
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 10,
paddingRight: 10,
paddingLeft: 20,
paddingRight: 20,
borderRadius: 5,
display: 'flex',
flexDirection: 'column',
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
backgroundColor: pageConfig.backgroundColor || '#ffffff'
},
ref: rootRef,
onLayout,
onTouchStart: () => {
ReactNative.Keyboard.isVisible() && ReactNative.Keyboard.dismiss()
}
onLayout
},
createElement(RouteContext.Provider,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
{ padding: 0, backgroundColor: '#fff' },
style,
multiline && autoHeight
? { height: Math.max((style as any)?.minHeight || 35, contentHeight) }
? { minHeight: Math.max((style as any)?.minHeight || 35, contentHeight) }
: {}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
const intersectionObservers = useContext(IntersectionObserverContext)

const snapScrollIntoView = useRef<string>('')
const firstScrollIntoViewChange = useRef<boolean>(false)

const {
normalStyle,
Expand Down Expand Up @@ -220,23 +220,28 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
}, [refresherTriggered])

useEffect(() => {
if (scrollIntoView && __selectRef && snapScrollIntoView.current !== scrollIntoView) {
snapScrollIntoView.current = scrollIntoView || ''
setTimeout(() => {
const refs = __selectRef(`#${scrollIntoView}`, 'node')
if (refs) {
const { nodeRef } = refs.getNodeInstance()
nodeRef.current?.measureLayout(
scrollViewRef.current,
(left: number, top:number) => {
scrollToOffset(left, top)
}
)
}
})
if (scrollIntoView && __selectRef) {
if (!firstScrollIntoViewChange.current) {
setTimeout(handleScrollIntoView)
} else {
handleScrollIntoView()
}
}
firstScrollIntoViewChange.current = true
}, [scrollIntoView])

function handleScrollIntoView () {
const refs = __selectRef!(`#${scrollIntoView}`, 'node')
if (!refs) return
const { nodeRef } = refs.getNodeInstance()
nodeRef.current?.measureLayout(
scrollViewRef.current,
(left: number, top:number) => {
scrollToOffset(left, top)
}
)
}

function selectLength (size: { height: number; width: number }) {
return !scrollX ? size.height : size.width
}
Expand Down

0 comments on commit a2ca855

Please sign in to comment.