Skip to content

Commit 2d7fa8f

Browse files
committed
bug fix issue #1
1 parent 10c3c2e commit 2d7fa8f

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

src/Components/Hospital.tsx

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import React from 'react';
2-
import { Text, View, StyleSheet } from 'react-native';
1+
import React, { useState } from 'react';
2+
import { Text, View, StyleSheet, Modal, Dimensions } from 'react-native';
33
import { Card, Button } from 'react-native-elements';
44
import { colors } from '../Theme';
55
import Supply from './Supply';
66
import moment from 'moment';
7+
import HospitalDetail from './HospitalDetail';
8+
const { height } = Dimensions.get('window');
79

810
type PropTypes = {
911
item: HospitalType;
10-
onClick: (hospital: HospitalType) => void;
1112
};
1213

1314
const styles = StyleSheet.create({
@@ -29,8 +30,9 @@ const styles = StyleSheet.create({
2930
},
3031
});
3132

32-
function Hospital({ item, onClick }: PropTypes) {
33+
function Hospital({ item }: PropTypes) {
3334
const { supplies } = item;
35+
const [visible, setVisible] = useState(false);
3436
return (
3537
<Card title={item.hospital}>
3638
<View style={styles.subtitleContainer}>
@@ -52,7 +54,36 @@ function Hospital({ item, onClick }: PropTypes) {
5254
</View>
5355
</View>
5456
<View style={{ paddingHorizontal: 30, paddingTop: 10 }}>
55-
<Button type="outline" title="查看详情" onPress={() => onClick(item)} />
57+
<Button
58+
type="outline"
59+
title="查看详情"
60+
onPress={() => setVisible(true)}
61+
/>
62+
<Modal
63+
animationType="fade"
64+
presentationStyle="formSheet"
65+
transparent={false}
66+
onDismiss={() => {
67+
setVisible(false);
68+
}}
69+
onRequestClose={() => {
70+
setVisible(false);
71+
}}
72+
visible={visible}>
73+
<View style={{ padding: 16, justifyContent: 'space-between' }}>
74+
<View style={{ height: height - 150 }}>
75+
<HospitalDetail item={item} />
76+
</View>
77+
<View>
78+
<Button
79+
title="关闭详情"
80+
onPress={() => {
81+
setVisible(false);
82+
}}
83+
/>
84+
</View>
85+
</View>
86+
</Modal>
5687
</View>
5788
</Card>
5889
);

src/Layouts/Hospital.tsx

+1-31
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function HospitalLayout() {
2626
'https://vuqjf9paihid.leanapp.cn/supplies/requirement',
2727
);
2828
const [refreshing, setRefreshing] = useState(false);
29-
const [selected, setSelection] = useState<HospitalType | null>(null);
3029

3130
const hospitals: HospitalType[] = data || [];
3231

@@ -38,11 +37,8 @@ function HospitalLayout() {
3837
});
3938
}
4039

41-
function onClick(hospital: HospitalType) {
42-
setSelection(hospital);
43-
}
4440
function renderItem({ item }: { item: HospitalType }) {
45-
return <Hospital item={item} onClick={onClick} />;
41+
return <Hospital item={item} />;
4642
}
4743

4844
return (
@@ -67,32 +63,6 @@ function HospitalLayout() {
6763
) : null
6864
}
6965
/>
70-
71-
<Modal
72-
animationType="slide"
73-
presentationStyle="formSheet"
74-
transparent={false}
75-
onDismiss={() => {
76-
setSelection(null);
77-
}}
78-
onRequestClose={() => {
79-
setSelection(null);
80-
}}
81-
visible={selected !== null}>
82-
<View style={{ padding: 16, justifyContent: 'space-between' }}>
83-
<View style={{ height: height - 150 }}>
84-
{selected && <HospitalDetail item={selected} />}
85-
</View>
86-
<View>
87-
<Button
88-
title="关闭详情"
89-
onPress={() => {
90-
setSelection(null);
91-
}}
92-
/>
93-
</View>
94-
</View>
95-
</Modal>
9666
</StatusBarSafeLayout>
9767
);
9868
}

0 commit comments

Comments
 (0)