React Native Modal样式

时间:2019-01-10 13:53:47

标签: javascript reactjs react-native

所以,我在react native中有一个模态,它占据了我的整个屏幕,我不希望这种情况发生,任何想法如何配置它? 我有以下结构

f.name

包装器组件的结构是

<Modal visible={props.display} animationType="slide" style={{
    width: '50%',
    height: '50%'}}>
      <Wrapper>
          <ShiftDeclinedWrapper>
            <CenterText padding="20px">{props.data}</CenterText>
            <Footer>
              <ButtonWrapper>
                <Button
                  isDisabled={props.isLoading}
                  onPress={() => props.declineAccept()}
                  textColor="white"
                  color={theme.color.red}>
                  Decline
                </Button>
              </ButtonWrapper>
              <ButtonWrapper>
                <Button
                  isDisabled={props.isLoading}
                  onPress={props.declineBack}
                  textColor="white"
                  color={theme.color.green}>
                  No, thanks
                </Button>
              </ButtonWrapper>
            </Footer>
          </ShiftDeclinedWrapper>
      </Wrapper>
    </Modal>

ShiftDeclineWrapper只是

export const Wrapper = styled.View`
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  flex: 1;
`;

我已经尝试过将宽度/高度设置为50%,以便可以确保它能按我的喜好对其进行样式设置,我尝试将其放在模式,包装器上,也将shiftdeclinewrapper放在上面也没用

2 个答案:

答案 0 :(得分:1)

根据Modal文档here,您不能为此使用style道具。

您可以将样式添加到<Wrapper>元素中,并将道具transparent添加到Modal中以获得透明的背景(而不是默认的白色)。

<Modal visible={props.display} animationType="slide" transparent>
  <Wrapper style={{width: '50%', height: '50%'}}>

您还必须在style组件上使用<Wrapper>道具。

答案 1 :(得分:0)

这对我有用!

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim StuName = InputBox("Enter Student name")
    'Loop until a name is entered.
    Do While String.IsNullOrWhiteSpace(StuName)
        StuName = InputBox("You must enter a name before recording grades")
    Loop
    Dim stu As New StudentGrades(StuName)
    Dim MBResult As DialogResult
    'Loop until user is done entering scores for this student.
    Do
        Dim strScore = InputBox($"Enter the score for test {stu.StudentName}")
        If Not ValidateScore(strScore) Then
            'Loop until user enters a valid score.
            Do
                strScore = InputBox("You must enter a number between 0 and 100")
            Loop Until ValidateScore(strScore)
        End If
        stu.TestScores.Add(CInt(strScore))
        MBResult = MessageBox.Show($"Add another score for {StuName}?", "Add Another?", MessageBoxButtons.YesNo)
    Loop Until MBResult = DialogResult.No
    stu.SetAverage()
    StuList.Add(stu)
End Sub

Private Function ValidateScore(strScore As String) As Boolean
    Dim score As Integer
    If Integer.TryParse(strScore, score) AndAlso score >= 0 AndAlso score <= 100 Then
        Return True
    End If
    Return False
End Function

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    DataGridView1.DataSource = StuList
End Sub