簡體   English   中英

react-native 紙按鈕矢量圖標向右浮動

[英]react-native paper button vector-icons float right

我嘗試用 V 形圖標構建一個 accordeonmenu 我的 headerbutton 有以下代碼:

const AccordeonHeader = (Props) => {
        return(
            <View style={[accordionStyles.header]}>
                    <Button
                        contentStyle={[accordionStyles.header__button, ]}
                        color='black'
                        onPress={() => {show !== Props.value ? setShow(Props.value) : setShow(false)}}
                    >   
                        <Text
                            style={[accordionStyles.header__text, styles.headline__h2]}
                        >
                            {Props.label}
                        </Text>
                            
                        <Icon 
                            iconStyle={[accordionStyles.header__icon,]} 
                            name={show === Props.value ? "chevron-up" : "chevron-down"}
                        >
                        </Icon>  
                                           
                    </Button>
                </View>
        );
    }

有了這個 styles

const accordionStyles = StyleSheet.create({
    header: {

    },
    header__button: {
        width:'100%',
        borderColor:'green',
        borderWidth:2,
        flexDirection:'row',
        justifyContent:'space-between',
    },
    header__text: {
        display:'none',
        color:'black',
    },
    header__icon: {
        alignSelf:'flex-end',
        color:'black',
    },
   
  });

但我無法在右側獲得圖標,文本留在左側。 它總是在旁邊。 帶有文本和圖標的手風琴標頭按鈕

更新

import * as React from 'react';
import { Text, View, StyleSheet ,Button,TouchableOpacity} from 'react-native';
import Constants from 'expo-constants';
import FontAwesome from "react-native-vector-icons/FontAwesome";

export default function App() {
  return (
    <TouchableOpacity style={[accordionStyles.header]} onPress={()=>console.log("press")}>        
          <Text style={{paddingTop:5}}>Sortieren</Text>
          <FontAwesome
            iconStyle={[accordionStyles.header__icon]}
            size={30}
            color="#000000" 
            name={"chevron-up"}
          />        
      </TouchableOpacity>
  );
}

const accordionStyles = StyleSheet.create({
  header: { 
    width: "100%",
  borderColor: "green",
  borderWidth: 2,
  flexDirection: "row",
  justifyContent: "space-between"},  
  header__icon: {
    alignSelf: "flex-end",
    color: "black"
  }
});

在此處輸入圖像描述

零食代碼

它非常簡單,只需添加,

contentStyle={{flexDirection: 'row-reverse'}}

我們的圖標移到右側

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM