-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66e2cf3
commit 87eb1e4
Showing
10 changed files
with
517 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,58 @@ | ||
import React from 'react'; | ||
import {Text, View} from 'react-native'; | ||
import {Picker, Button} from '@uiw/react-native'; | ||
import {SafeAreaView} from 'react-native'; | ||
import {Picker, Button, Spacing} from '@uiw/react-native'; | ||
import {ComProps} from '../../routes'; | ||
import Layout, {Container} from '../../Layout'; | ||
const {Header, Body, Footer} = Layout; | ||
|
||
export interface BadgeViewProps extends ComProps {} | ||
export interface PickerViewProps extends ComProps {} | ||
|
||
export default class BadgeView extends React.Component<BadgeViewProps> { | ||
state = { | ||
value: 1, | ||
}; | ||
render() { | ||
const {route, navigation} = this.props; | ||
const description = route.params.description; | ||
const title = route.params.title; | ||
const arr = []; | ||
for (let i = 0; i < 100; i++) { | ||
arr.push({label: i}); | ||
} | ||
return ( | ||
<Container scrollEnabled={false}> | ||
<Layout> | ||
<Header title={title} description={description} /> | ||
<Body scrollEnabled={false}> | ||
<View | ||
style={{ | ||
flex: 1, | ||
flexDirection: 'row', | ||
backgroundColor: '#fff', | ||
marginTop: 20, | ||
paddingVertical: 20, | ||
}}> | ||
<View style={{width: '50%'}}> | ||
<Picker data={arr as any} value={17} /> | ||
</View> | ||
<View style={{width: '50%'}}> | ||
<Picker | ||
onChange={val => { | ||
console.log('val: ', val); | ||
}} | ||
data={arr as any} | ||
value={this.state.value} | ||
/> | ||
</View> | ||
</View> | ||
<Button | ||
onPress={() => { | ||
this.setState({value: this.state.value + 1}); | ||
}}> | ||
控制第二列value | ||
</Button> | ||
</Body> | ||
<Footer /> | ||
</Layout> | ||
</Container> | ||
); | ||
} | ||
export default function (props: PickerViewProps) { | ||
const [value, setValue] = React.useState(['2', '22', '221']); | ||
const [value2, setValue2] = React.useState(['5']); | ||
const [visible, setVisible] = React.useState(false); | ||
const arr = [ | ||
{ | ||
label: '江苏省', | ||
value: '1', | ||
children: [ | ||
{ | ||
label: '南京市', | ||
value: '11', | ||
children: [ | ||
{label: '宣武区', value: '111'}, | ||
{label: '雨花台区', value: '112'}, | ||
], | ||
}, | ||
{ | ||
label: '苏州市', | ||
value: '12', | ||
children: [{label: '苏州区', value: '121'}], | ||
}, | ||
], | ||
}, | ||
{label: '北京市', value: '2', children: [{label: '北京市', value: '22', children: [{label: '朝阳区', value: '221'}]}]}, | ||
]; | ||
|
||
const arr2 = [ | ||
{label: '3', value: '3'}, | ||
{label: '4', value: '4'}, | ||
{label: '5', value: '5'}, | ||
]; | ||
|
||
return ( | ||
<SafeAreaView style={{flex: 1}}> | ||
<Button onPress={() => setVisible(true)}>打开</Button> | ||
<Picker | ||
title="标题" | ||
displayType="modal" | ||
value={value} | ||
onChange={(val: any) => setValue(val)} | ||
visible={visible} | ||
cols={3} | ||
onClosed={() => setVisible(false)} | ||
data={arr as any} | ||
/> | ||
<Spacing /> | ||
<Picker cols={1} displayType="view" data={arr2 as any} value={value2} onChange={(val2: any) => setValue2(val2)} /> | ||
</SafeAreaView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/core/src/Picker/components/WheelPicker/WheelPickerItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { memo } from 'react'; | ||
import { Animated, StyleSheet, Text } from 'react-native'; | ||
|
||
import { WhellPickerItemProps } from './type'; | ||
|
||
const opacityFunction = (val: number) => 1 / (1 + Math.abs(val)); | ||
const scaleFunction = (val: number) => 1 - 0.1 * Math.abs(val); | ||
const rotationFunction = (val: number) => 20 * val; | ||
|
||
function WheelPickerItem({ textStyle, style, visibleRest, height, option, index, currentIndex }: WhellPickerItemProps) { | ||
const relativeScrollIndex = Animated.subtract(index, currentIndex); | ||
|
||
const inputRange = [0]; | ||
for (let i = 1; i <= visibleRest + 1; i++) { | ||
inputRange.unshift(-i); | ||
inputRange.push(i); | ||
} | ||
|
||
const opacityOutputRange = [1]; | ||
for (let x = 1; x <= visibleRest + 1; x++) { | ||
const y = opacityFunction(x); | ||
opacityOutputRange.unshift(y); | ||
opacityOutputRange.push(y); | ||
} | ||
|
||
const scaleOutputRange = [1.0]; | ||
for (let x = 1; x <= visibleRest + 1; x++) { | ||
const y = scaleFunction(x); | ||
scaleOutputRange.unshift(y); | ||
scaleOutputRange.push(y); | ||
} | ||
|
||
const rotateXOutputRange = ['0deg']; | ||
for (let x = 1; x <= visibleRest + 1; x++) { | ||
const y = rotationFunction(x); | ||
rotateXOutputRange.unshift(`${y}deg`); | ||
rotateXOutputRange.push(`${y}deg`); | ||
} | ||
|
||
const opacity = relativeScrollIndex.interpolate({ inputRange, outputRange: opacityOutputRange }); | ||
const scale = relativeScrollIndex.interpolate({ inputRange, outputRange: scaleOutputRange }); | ||
const rotateX = relativeScrollIndex.interpolate({ inputRange, outputRange: rotateXOutputRange }); | ||
|
||
return ( | ||
<Animated.View style={[styles.option, style, { height, opacity, transform: [{ rotateX }, { scale }] }]}> | ||
<Text style={textStyle}>{option?.label}</Text> | ||
</Animated.View> | ||
); | ||
} | ||
|
||
export default WheelPickerItem; | ||
|
||
const styles = StyleSheet.create({ | ||
option: { | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
zIndex: 100, | ||
}, | ||
}); |
Oops, something went wrong.