flexDirection: แถวไม่ทำงานแบบโต้ตอบ

ฉันกำลังพัฒนาแอปพลิเคชันแบบรีแอคทีฟ หน้าจอแอปใดหน้าจอหนึ่งมีรายการอัลบั้ม ฉันได้แบ่งแต่ละคอนเทนเนอร์อัลบั้มออกเป็นส่วนประกอบต่างๆ ได้แก่ Card และ CardSection

การ์ดสามารถประกอบด้วย CardSections ได้หลายส่วน CardSection จะมีรูปภาพและ 2 ชื่อข้อความ ปัญหาที่ฉันกำลังเผชิญคือการวางตำแหน่งเนื้อหาใน CardSection เนื่องจาก flexDirection:'row' ไม่ทำงาน

นี่คือ CardSection.js

import React from 'react';
import {View, Text, Image} from 'react-native';

import Card from './Card';
import CardSection from "./CardSection";
const AlbumDetail = ({album}) => {

// destructing the props
const {title, artist, thumbnail_image} = album;
return (
    <Card>
        <CardSection>

            <View style={styles.thumbnailContainerStyle}>
                <Image style={styles.thumbnailStyle} source={{uri: thumbnail_image}} />
            </View>

            <View style={styles.headerContentStyle} >
                <Text style={styles.headerTextStyle}>{title}</Text>
                <Text>{artist}</Text>
            </View>

        </CardSection>
    </Card>
);
};

const styles = {
  headerContentStyle: {
     flexDirection: 'column',
     justifyContent: 'space-around'
},
headerTextStyle:{
    fontSize:18
},
thumbnailStyle: {
    height: 50,
    width: 50
},
thumbnailContainerStyle: {
    justifyContent: 'center',
    alignItems: 'center',
    margin: 10,
    marginRight: 10
}
};

export default AlbumDetail;

นี่คือ CardSection.js

import React from 'react';

import {View} from 'react-native';


const CardSection = (props) => {
return (
    <View styles={styles.containerStyle}>
        {props.children}
    </View>
);

};

const styles = {
 containerStyle: {
    borderBottomWidth: 1,
    padding: 5,
    backgroundColor: '#fff',
    justifyContent: 'flex-start',
    flexDirection: "row",
    borderColor: '#ddd',
    position: 'relative'
}
};
export default CardSection;

ผลลัพธ์ควรที่รูปภาพวางไว้ทางด้านซ้ายและทางด้านขวาของรูปภาพจะมีชื่อข้อความ 2 ชื่อและ flexDirection จะเป็น column

ExpectedResult ปัญหา


person Atif Javed    schedule 07.07.2018    source แหล่งที่มา
comment
วิธีที่ดีที่สุดในการดีบักคือติดตั้ง react-devtools และเลือก show inspector เพื่อช่วยคุณแก้ไขปัญหานี้ สำหรับฉันทุกอย่างดูดี   -  person Ashwin Mothilal    schedule 08.07.2018
comment
ใช่ ทุกอย่างดี แต่ฉันไม่รู้ว่าทำไมมันไม่ทำงาน ขอบคุณ ฉันจะติดตั้งมัน   -  person Atif Javed    schedule 08.07.2018


คำตอบ (4)


<View styles={styles.containerStyle}> คุณพิมพ์ผิด มันคือ styles อุปกรณ์ประกอบฉากควรเป็น style

person Noitidart    schedule 07.07.2018
comment
ขอบคุณสำหรับคำตอบของคุณ แต่มันก็ไม่ได้ผล นี่คือภาพหน้าจอ: prnt.sc/k3w89c - person Atif Javed; 08.07.2018
comment
เท่าที่ฉันคิดว่าปัญหาอยู่ใน CardSection.js flexDirection: 'column' จะยังคงเป็นคอลัมน์เหมือนกับชื่อข้อความ flexDirection: 'แถว' ใน CardSection.js ไม่ทำงาน containerStyle: { borderBottomWidth: 1, padding: 5, backgroundColor: '#fff', justifyContent: 'flex-start', flexDirection: "row", borderColor: '#ddd', position: 'relative' } - person Atif Javed; 08.07.2018
comment
ตรงเป้า.... ตรงเป้า... ราวกับว่าคุณดูรหัสของฉัน... - person Naveen R; 23.08.2020
comment
นี่เป็นปัญหาของฉันเหมือนกัน T__T - person Sam Lahm; 05.04.2021

ใช้สิ่งนี้

headerContentStyle: {
     flexDirection: 'row',
     justifyContent: 'space-around'
}

แทน

headerContentStyle: {
     flexDirection: 'column',
     justifyContent: 'space-around'
}
person akshay gore    schedule 08.07.2018
comment
ขอบคุณสำหรับคำตอบของคุณ แต่มันก็ไม่ได้ผล นี่คือภาพหน้าจอ: prnt.sc/k3w89c - person Atif Javed; 08.07.2018
comment
เท่าที่ฉันคิดว่าปัญหาอยู่ใน CardSection.js flexDirection: 'column' จะยังคงเป็นคอลัมน์เหมือนกับชื่อข้อความ flexDirection: 'แถว' ใน CardSection.js ไม่ทำงาน containerStyle: { borderBottomWidth: 1, padding: 5, backgroundColor: '#fff', justifyContent: 'flex-start', flexDirection: "row", borderColor: '#ddd', position: 'relative' } - person Atif Javed; 08.07.2018

คุณต้องใช้อุปกรณ์ประกอบฉากการ์ดคอนเทนเนอร์สไตล์ในไฟล์ CardSection.js คุณควรต้องใช้ flexDirection :'row' ที่นั่น หวังว่ามันจะได้ผล

person Savinder Singh    schedule 10.01.2019

ฉันมีปัญหาคล้ายกัน โดยที่ flexDirection: 'row' ไม่ทำงานในองค์ประกอบหนึ่งของฉันที่ฉันกำลังนำเข้าใน App.js

สาเหตุที่ทำให้เกิดสิ่งนี้คือ alignItems: 'center' ในสไตล์ชีตสำหรับคอนเทนเนอร์หลักในไฟล์ App.js ของฉัน

ฉันหวังว่านี่จะช่วยใครซักคน

person Codebender    schedule 19.01.2019