React本地物品响应迅速

发布于 2025-02-06 19:06:41 字数 3441 浏览 2 评论 0原文

在正确和不正确的项目堆叠之间的示例

请访问图像。我有一个屏幕宽度为1440px,一个带有1080px的屏幕宽度。在1440屏幕上,该项目堆叠在两列结构中。在1080上,一切都堆叠在左列。有没有办法编写javascript函数,该功能查看设备宽度并设置项目以进行相应调整?

const Complex = () => {
return (
    <View style={{ flex: 1 }}>
        <CarouselCards />
        <Divider
            style={{
                color: 'black',
                backgroundColor: 'black',
                marginHorizontal: 15,
            }}
        />
        <ScrollView horizontal={false}>
            <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
                {KPI.map((item) => (
                    <View style={styles.cardContainer} key={item.id}>
                        <View style={{ flexDirection: 'row' }}>
                            <View
                                style={{
                                    flex: 1,
                                    flexWrap: 'wrap',
                                }}
                            >
                                <View style={styles.cardContent}>
                                    <Text style={styles.cardTitle}>{item.title}</Text>
                                    <Text style={styles.bigFatNumber}>{item.value}</Text>
                                    <Text style={styles.smallKPI}>{item.kpi}</Text>
                                    <View style={{display:' flex'}}>

                                    <BarChart
                                        style={{ height: 100, width: 130 }}
                                        data={barData}
                                        svg={{ fill }}
                                        contentInset={{ top: 1, bottom: 30 }}
                                    ></BarChart>
                                    </View>

                                </View>
                            </View>
                        </View>
                    </View>
                ))}
            </View>
        </ScrollView>
    </View>
)

导出默认复合物

const styles = StyleSheet.create({
cardContainer: {
    backgroundColor: '#fff',
    width: 168,
    height: 190,
    margin: 15,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: {
        width: 0,
        height: 3,
    },
    shadowOpacity: 0.29,
    shadowRadius: 4.65,
    elevation: 7,
    padding: 15,
},
chartContainer: {
    backgroundColor: '#fff',
    width: 168,
    height: '100%',
    margin: 15,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: {
        width: 0,
        height: 3,
    },
    shadowOpacity: 0.29,
    shadowRadius: 4.65,
    elevation: 7,
    padding: 15,
    flexWrap: 'wrap',
    display: 'flex',
},
cardTitle: {
    // letterSpacing: 0.25,
    fontStyle: 'normal',
    fontSize: 14,
},
cardContent: {
    alignItems: 'flex-start',
    flexWrap: 'wrap',
    gap: 6,
    paddingVertical: 5,
},
bigFatNumber: {
    letterSpacing: 0.25,
    lineHeight: 36,
    fontWeight: 'bold',
    fontStyle: 'normal',
    fontSize: 24,
},
smallKPI: {
    letterSpacing: 0.25,
    lineHeight: 24,
    fontWeight: 'bold',
    fontStyle: 'normal',
    fontSize: 14,
    order: 1,
    color: 'rgba(0, 0, 0, 0.6)',
},

})

Example between correct and incorrect item stacking

Please refere to the image. I have twee phones one with a screen width of 1440px and one with 1080px.On the 1440 screen the items are stacked in a two column structure. On the 1080 everything gets stacked on the left column. Is there a way to write a javascript function that looks at the device width and sets the item to adjust accordingly?

const Complex = () => {
return (
    <View style={{ flex: 1 }}>
        <CarouselCards />
        <Divider
            style={{
                color: 'black',
                backgroundColor: 'black',
                marginHorizontal: 15,
            }}
        />
        <ScrollView horizontal={false}>
            <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
                {KPI.map((item) => (
                    <View style={styles.cardContainer} key={item.id}>
                        <View style={{ flexDirection: 'row' }}>
                            <View
                                style={{
                                    flex: 1,
                                    flexWrap: 'wrap',
                                }}
                            >
                                <View style={styles.cardContent}>
                                    <Text style={styles.cardTitle}>{item.title}</Text>
                                    <Text style={styles.bigFatNumber}>{item.value}</Text>
                                    <Text style={styles.smallKPI}>{item.kpi}</Text>
                                    <View style={{display:' flex'}}>

                                    <BarChart
                                        style={{ height: 100, width: 130 }}
                                        data={barData}
                                        svg={{ fill }}
                                        contentInset={{ top: 1, bottom: 30 }}
                                    ></BarChart>
                                    </View>

                                </View>
                            </View>
                        </View>
                    </View>
                ))}
            </View>
        </ScrollView>
    </View>
)

export default Complex

const styles = StyleSheet.create({
cardContainer: {
    backgroundColor: '#fff',
    width: 168,
    height: 190,
    margin: 15,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: {
        width: 0,
        height: 3,
    },
    shadowOpacity: 0.29,
    shadowRadius: 4.65,
    elevation: 7,
    padding: 15,
},
chartContainer: {
    backgroundColor: '#fff',
    width: 168,
    height: '100%',
    margin: 15,
    borderRadius: 8,
    shadowColor: '#000',
    shadowOffset: {
        width: 0,
        height: 3,
    },
    shadowOpacity: 0.29,
    shadowRadius: 4.65,
    elevation: 7,
    padding: 15,
    flexWrap: 'wrap',
    display: 'flex',
},
cardTitle: {
    // letterSpacing: 0.25,
    fontStyle: 'normal',
    fontSize: 14,
},
cardContent: {
    alignItems: 'flex-start',
    flexWrap: 'wrap',
    gap: 6,
    paddingVertical: 5,
},
bigFatNumber: {
    letterSpacing: 0.25,
    lineHeight: 36,
    fontWeight: 'bold',
    fontStyle: 'normal',
    fontSize: 24,
},
smallKPI: {
    letterSpacing: 0.25,
    lineHeight: 24,
    fontWeight: 'bold',
    fontStyle: 'normal',
    fontSize: 14,
    order: 1,
    color: 'rgba(0, 0, 0, 0.6)',
},

})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏半生如梦愿梦如真 2025-02-13 19:06:41

您可以使用device -width具有尺寸,您可以在react react本地获得 - https://reactnative.dev/dev/dev/dev/docs/docs/docs/docs/dimensions/dimensions/dimensions 。是的,添加您的物品固定宽度(例如(宽度YOURMARGIN) / 3),或者您可以使用Flex且不使用固定宽度。

You can get device-width with Dimensions that you get in React native - https://reactnative.dev/docs/dimensions. Yust add your items fixed width(something like (width-yourMargin) / 3) or you can use flex and not use fixed width.

卷耳 2025-02-13 19:06:41
  1. 使用

react-nortage-noreative-responsive-dimensions

Windows的NPM安装

npm i react-native-responsive-dimensions

  1. 使用该导入
import {
  responsiveHeight as rh,
  responsiveWidth as rw,
  responsiveFontSize as rf,
} from "react-native-responsive-dimensions";

  1. 如何使用
width:rw(100),
height:rh((100),
fontSize:rf(1.5),

  1. use

react-native-responsive-dimensions

use key word npm install for windows

npm i react-native-responsive-dimensions

  1. import using that

import {
  responsiveHeight as rh,
  responsiveWidth as rw,
  responsiveFontSize as rf,
} from "react-native-responsive-dimensions";

  1. how to use

width:rw(100),
height:rh((100),
fontSize:rf(1.5),

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文