最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Center React Native Paper Modal - Stack Overflow

programmeradmin0浏览0评论

I might be missing something small here but I can't seem to get my <Modal> ponent to center in my React Native app. Here is the code for the modal:

...
            <Portal>
                <Modal
                    visible={modalVisible}
                    onDismiss={hideModal}
                    contentContainerStyle={{
                        backgroundColor:'white',
                        padding:20,
                        width:'90%'
                    }}
                >
                    <ScrollView>
                        <Text>A long chunk of text</Text>
                        <Button
                            onPress={hideModal}
                            color='#5F9DA5'
                            mode='contained'
                            dark={true}
                        >
                            Cool!
                        </Button>
                    </ScrollView>
                </Modal>
            </Portal>
...

I tried doing this as well:

                <Modal
                    visible={modalVisible}
                    onDismiss={hideModal}
                    contentContainerStyle={{
                        backgroundColor:'white',
                        padding:20,
                        width:'90%',
                        flex: 1,
                        alignItems: 'center',
                        justifyContent: 'center'
                    }}
                >

Unsure what I'm missing here.

I might be missing something small here but I can't seem to get my <Modal> ponent to center in my React Native app. Here is the code for the modal:

...
            <Portal>
                <Modal
                    visible={modalVisible}
                    onDismiss={hideModal}
                    contentContainerStyle={{
                        backgroundColor:'white',
                        padding:20,
                        width:'90%'
                    }}
                >
                    <ScrollView>
                        <Text>A long chunk of text</Text>
                        <Button
                            onPress={hideModal}
                            color='#5F9DA5'
                            mode='contained'
                            dark={true}
                        >
                            Cool!
                        </Button>
                    </ScrollView>
                </Modal>
            </Portal>
...

I tried doing this as well:

                <Modal
                    visible={modalVisible}
                    onDismiss={hideModal}
                    contentContainerStyle={{
                        backgroundColor:'white',
                        padding:20,
                        width:'90%',
                        flex: 1,
                        alignItems: 'center',
                        justifyContent: 'center'
                    }}
                >

Unsure what I'm missing here.

Share Improve this question asked Mar 23, 2022 at 19:37 patataskrpatataskr 3531 gold badge6 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Try adding alignSelf:"center" to contentContainerStyle

发布评论

评论列表(0)

  1. 暂无评论