【发布时间】:2021-03-09 08:48:48
【问题描述】:
当我点击 Ionicon 时,我应该只看到 ActivityIndicator,但它是白色的,但 ActivityIndicator 永远不会停止工作。
它应该在getSamplesToChoose 函数完成其操作时停止。
函数 getSamplesToChoose
function getSamplesToChoose() {
const fromDate = params.fromDate;
const toDate = params.toDate;
console.log('getSamplesToChoose for ws:', selectedWaterSource);
if (selectedWaterSource.length === 0) {
Toast.show({ text1: 'no choose points' });
return;
}
(async () => {
const wsRequestCount = await wsSampleRequestBySource(
// check webservice
selectedWaterSource,
fromDate,
toDate
);
if (wsRequestCount === 0) {
//no requests from server
Toast.show({
text1: 'no drishot:' + fromDate + ' lebein:' + toDate,
text2: selectedWaterSource + ' points: ',
});
}
// updated db
const requestList = await getRequestBySourceAndDates(
selectedWaterSource,
fromDate,
toDate
);
if (requestList.length > 0) {
// there are requests. move to next screen with list
navigation.navigate('list of drishot', {
paramsFromNekudotDigum: {
requestList,
fromDate: date1.toISOString().slice(0, 10),
toDate: date2.toISOString().slice(0, 10),
},
});
}
toggleLoading(false);
})();
}
import {ActivityIndicator} from 'react-native';
export default function tomato() {
const [isLoading, toggleLoading] = useState(false);
return (
<TouchableOpacity
activeOpacity={1}
onPress={!isLoading ? () => {
toggleLoading(true);
getSamplesToChoose();
} : null}
>
<View>
<NavigationDialog />
</View>
{
isLoading ?
<View style={styles.indicator}>
<ActivityIndicator size="large" color="#4abdff" />
</View>
:
<Ionicon
style={{ bottom: -10 }}
name="md-checkmark-circle-outline"
size={30}
color={
Array.isArray(selectedWaterSource) === true &&
selectedWaterSource.length > 0
? 'white'
: 'gray'}
/>
}
</TouchableOpacity>
);
}
【问题讨论】:
-
请分享此文件中的其余代码。如果我能看到 getSamplesToChoose 函数代码,我只能提供帮助
-
我添加它..你可以看到我的编辑。
标签: javascript reactjs react-native activity-indicator