Skip to content

Commit 4837e26

Browse files
author
hy
committed
解决折叠卡片列表点击折叠报错
1 parent e87a77e commit 4837e26

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

example/examples/src/routes/CardCollapse/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import {ScrollView, View, Image} from 'react-native';
3-
import {CardCollapse} from '@uiw/react-native';
2+
import { ScrollView, View, Image } from 'react-native';
3+
import { CardCollapse } from '@uiw/react-native';
44
import Layout from '../../Layout';
55
import map from 'lodash/map';
66

@@ -12,20 +12,20 @@ const contents = [
1212
];
1313

1414
const CardCollapseDemo = (props: any) => {
15-
const {Header} = Layout;
16-
const {route} = props;
15+
const { Header } = Layout;
16+
const { route } = props;
1717
const description = route.params.description;
1818
const title = route.params.title;
1919

2020
const renderItem = (_: string, index: number) => {
2121
return (
22-
<View key={index} style={{padding: 12}}>
23-
<Image source={{uri: contents[index]}} style={{height: 180}} />
22+
<View key={index} style={{ padding: 12 }}>
23+
<Image source={{ uri: contents[index] }} style={{ height: 180 }} />
2424
</View>
2525
);
2626
};
2727
return (
28-
<ScrollView style={{flex: 1}}>
28+
<ScrollView style={{ flex: 1 }}>
2929
<Header title={title} description={description} />
3030
<Header description={'基本使用'} />
3131
<CardCollapse isCollapsed={false} disablePresses={false}>

packages/core/src/CardCollapse/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const contents = [
2323

2424
class Demo extends Component {
2525
render() {
26-
const renderItem = (_, index) => {
26+
const renderItem = (_, index) => {
2727
return (
28-
<View key={index} style={{ padding: 18 }}>
29-
<Image source={{uri: contents[index]}} style={{ height: 150 }} />
28+
<View key={index} style={{ padding: 20,backgroundColor: '#fff'}}>
29+
<Image source={{uri: contents[index]}} style={{ height: 120 }} />
3030
</View>
3131
);
3232
}

packages/core/src/CardCollapse/index.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ export default function CardCollapse(props: CardCollapseProps) {
9292
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
9393
}, [collapsed]);
9494

95-
function getItemScale(index: number) {
96-
if (collapsed) {
97-
if (index === itemsCount - 2) {
98-
return 0.95;
99-
}
100-
if (index === itemsCount - 1) {
101-
return 0.9;
102-
}
103-
}
104-
return 1;
105-
}
10695
// 动画
10796
const animate = async () => {
10897
return Promise.all([animateValues(), animateCards()]);
@@ -133,6 +122,13 @@ export default function CardCollapse(props: CardCollapseProps) {
133122
});
134123
};
135124

125+
function getItemScale(index: number) {
126+
if (collapsed) {
127+
return 0.9;
128+
}
129+
return 1;
130+
}
131+
136132
const animateCards = () => {
137133
const promises = [];
138134
for (let index = 0; index < itemsCount; index++) {
@@ -210,21 +206,23 @@ export default function CardCollapse(props: CardCollapseProps) {
210206

211207
const renderItem = (item: JSX.Element | JSX.Element[], index: number) => {
212208
return (
213-
<Animated.View
209+
< Animated.View
214210
key={index}
215-
onLayout={index === 0 ? onLayout : undefined}
216-
style={[
217-
Platform.OS === 'ios' && styles.containerShadow,
218-
getStyle(index),
219-
{
220-
borderRadius: Platform.OS === 'ios' ? itemBorderRadius : undefined,
221-
alignSelf: 'center',
222-
zIndex: itemsCount - index,
223-
transform: [{ scaleX: animatedScaleArray[index] }],
224-
width: Dimensions.get('screen').width - 40,
225-
height: collapsed ? firstItemHeight : undefined,
226-
},
227-
]}
211+
onLayout={index === 0 ? onLayout : undefined
212+
}
213+
style={
214+
[
215+
Platform.OS === 'ios' && styles.containerShadow,
216+
getStyle(index),
217+
{
218+
borderRadius: Platform.OS === 'ios' ? itemBorderRadius : undefined,
219+
alignSelf: 'center',
220+
zIndex: itemsCount - index,
221+
transform: [{ scaleX: animatedScaleArray[index] }],
222+
width: Dimensions.get('screen').width - 40,
223+
height: collapsed ? firstItemHeight : undefined,
224+
},
225+
]}
228226
collapsable={false}
229227
>
230228
<Container
@@ -237,7 +235,7 @@ export default function CardCollapse(props: CardCollapseProps) {
237235
</Animated.View>
238236
</TouchableOpacity>
239237
</Container>
240-
</Animated.View>
238+
</Animated.View >
241239
);
242240
};
243241
return (

0 commit comments

Comments
 (0)