简体   繁体   English

如何将 css 应用于<text>内部组件<card.content> react-native-paper 中的组件?</card.content></text>

[英]How to apply css to the <Text> component inside <Card.Content> component from react-native-paper?

I am working on the React Native 0.62 in which i am using react-native-paper for card.我正在研究 React Native 0.62,我在其中使用 react-native-paper 作为卡片。 And i have used from react-native inside the Card.Content component.我在 Card.Content 组件中使用了 react-native 。 But the UI is not as expected as i want.但用户界面并不像我想要的那样。 I tried using nested componet it works but then other css won't apply to it like padding etc. Any help is appreciated.我尝试使用嵌套组件它可以工作,但是其他 css 不会像填充等一样适用于它。任何帮助表示赞赏。

Expected Output:预期 Output: 在此处输入图像描述

Current UI:当前用户界面: 在此处输入图像描述

Code:代码:

 <Card.Content style={{ paddingTop: 10 }}>
                {this.props.data.getHolidays.loading ?
                  (<View style={{ width: 'auto', height: 175, justifyContent: 'center', alignItems: 'center' }}><ActivityIndicator color="#6CCFF6" size="large" /></View>)
                  :
                  Object.keys(this.props.data.getHolidays.holidays).length == 0 ?
                    (<View style={{ width: 'auto', height: 175, justifyContent: 'center', alignItems: 'center' }}><Text style={{ fontFamily: 'OpenSans-Regular', fontSize: 14, color: 'black' }}>Not Available</Text></View>) :

                (
                  Object.keys(this.props.data.getHolidays.holidays).map(key => (
                    <>
                      <Caption style={{ fontFamily: 'OpenSans-Regular', fontSize: 14, color: '#CFCFCF', marginBottom: 10, }}>{key}</Caption >
                      {this.props.data.getHolidays.holidays[key].map((holidayList, index) => (                            

                        <View style={{ borderRadius: 5, backgroundColor: (index % 2 == 0) ? '#596AB2' : '#48657D', marginBottom: 10 }} key={index}>

                          <Text style={{ fontFamily: 'OpenSans-Regular', fontSize: 14, color: '#FFFFFF', paddingVertical: 6, paddingHorizontal: 10 }}>
                            {moment(holidayList.holidayDate).format('ddd')} {moment(holidayList.holidayDate).format('Do')} - {holidayList.holidayEvent}</Text>
                        </View>
                      ))}
                    </>
                  ))
                )
            }
          </Card.Content>

This has nothing to do with the Card styling when you place a text inside a view it takes the full space当您将文本放在视图中时,这与卡片样式无关,它会占用整个空间

You can put a assignSelf for wrapper view which will solve your problem.您可以为包装视图放置一个assignSelf,这将解决您的问题。

  <View
    style={{
      borderRadius: 5,
      backgroundColor: '#48657D',
      marginBottom: 10,
      alignSelf:'flex-start'
    }}>
    <Text
      style={{
        fontFamily: 'OpenSans-Regular',
        fontSize: 14,
        color: '#FFFFFF',
        paddingVertical: 6,
        paddingHorizontal: 10,
      }}>
      {"1232"}
      {"123"} -
      {"Event goes here"}
    </Text>
  </View>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM