Stack Overflow Asked by erv on December 5, 2021
I have a spinning loading wheel (implemented with <ActivityIndicator>
) inside a modal with lowered opacity. I want the modal to cover the full screen. The modal pops up after the user unlocks their account in another modal. The problem is that the ‘loading wheel’ modal only covers the part of the screen that wasn’t covered by the keyboard in the ‘unlock’ modal.
It would seem to be a timing issue as occasionally the ‘loading wheel’ modal does cover the whole screen. Here’s my react native modals:
<Modal visible={modalUnlockVisible} animationType={"none"}>
<Text>Enter Pin Code</Text>
<TextInput
maxLength={15}
secureTextEntry={true}
onChangeText={text => setPincode(text)}
/>
<Button
title="Unlock"
onPress={() => { Keyboard.dismiss(); unlock(pincode) }}
/>
</Modal>
<Modal visible={loader} transparent={true} animationType={"none"} style={styles.loader}>
<View style={styles.loaderBackground}>
<View style={styles.loaderFrame}>
<ActivityIndicator size="large" color="#006EFF"/>
</View>
</View>
</Modal>
......
//styles
loader: {
zIndex: 100
},
loaderBackground: {
top: 0,
left: 0,
bottom: 0,
right: 0,
flex: 1,
alignItems: 'center',
flexDirection: 'column',
backgroundColor: 'rgba(0,0,0,0.7)'
},
.....
So the top modal of the above two pops up, and the user unlocks by pressing the Unlock button calling unlock(pincode)
:
function unlock(pincode) {
setModalUnlockVisibility(false); // Hide 'unlock' modal
setLoader(true); // Show 'loading wheel' modal
.....
}
Any way to make the ‘loading’ modal cover the whole screen? I added in the Keyboard.dismiss()
before unlock(..)
in the hope that it might help, but the problem persists most of the time.
I solved this by using the Dimension
component from react-native
. As per this answer at SO.
import { Dimensions } from 'react-native'
^ at the top of your file where your component is. And in my case change my loaderBackground
style to:
loaderBackground: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
alignItems: 'center',
flexDirection: 'column',
backgroundColor: 'rgba(0,0,0,0.7)',
....
},
Answered by erv on December 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP