Javascript 如何在组件中的组件中启用Scrollview
我试图在我的主屏幕中添加Scrollview,在那里我显示了一系列产品。当我在屏幕上添加滚动视图时,它不会启用滚动功能。我制作了一个视图,其中一个组件正在渲染,每个组件都有自己的数组 代码 Newsfeed.jsJavascript 如何在组件中的组件中启用Scrollview,javascript,android,react-native,Javascript,Android,React Native,我试图在我的主屏幕中添加Scrollview,在那里我显示了一系列产品。当我在屏幕上添加滚动视图时,它不会启用滚动功能。我制作了一个视图,其中一个组件正在渲染,每个组件都有自己的数组 代码 Newsfeed.js import React, {Component} from 'react'; import {View, Text, TouchableOpacity,StyleSheet} from 'react-native'; import Connections from './Compo
import React, {Component} from 'react';
import {View, Text, TouchableOpacity,StyleSheet} from 'react-native';
import Connections from './Components/Connections';
import ClearStock from './Components/ClearStock';
import NewProducts from './Components/NewProducts';
import Discounts from './Components/Discounts';
import CustomButton from './Components/CustomButton';
import { ScrollView } from 'react-native';
// import {ScrollView} from 'react-native';
export default class NewsFeed extends Component {
state = {
selected: 'ClearStock',
};
buttonClick(name) {
this.setState({selected: name});
}
render() {
return (
<View>
<View style={{flexDirection: 'row',borderWidth:5,backgroundColor:'#ffc687'}}>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('ClearStock')}
iconName="stumbleupon-circle">
Clear Stock
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Discounts')}
iconName="home" >
Discounts
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('NewProducts')}
iconName="free-code-camp">
New Products
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Connections')}
iconName="home">
Connections
</CustomButton>
</View>
<View>
{this.state.selected === 'ClearStock' ? (
<ClearStock />
) : this.state.selected === 'Discounts' ? (
<Discounts />
) : this.state.selected === 'NewProducts' ? (
<NewProducts />
) : (
<Connections />
)}
</View>
</View>
);
}
}
styles=StyleSheet.create({
btnStyle:{
marginLeft:40,
// backgroundColor:'red',
borderRadius:10,
}
});
import React, { Component } from 'react';
import {ImageBackground, View, TouchableOpacity, StyleSheet, Image, Text, ScrollView } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class CustomCard extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
const { name, quantity, price, category, tags, color, imageUrl } = this.props.products;
return (
<View >
<ImageBackground
style={styles.productView}
source={{ uri: "https://www.akfoconee.com/wp-content/uploads/2017/12/kids-martial-arts-landing-page-section-two-background-min-min.png" }}
>
<View style={{ flexDirection: 'row' }}>
<Icon name="bullhorn" size={30} />
<View style={{ marginLeft: 30, padding: 10, height: "100%", borderRadius: 30, borderWidth: 1, borderColor: "orange", width: "30%" }}>
<Image style={{ marginLeft: 10, height: "100%", width: 100, resizeMode: "contain" }} source={{ uri: imageUrl }} />
</View>
<View style={{ padding: 1, marginLeft: 10 }}>
<Text> We are offering FLASH SALE</Text>
<Text style={styles.itemDescription}>{name}</Text>
<Text style={styles.itemDescription}>{quantity}</Text>
<Text style={styles.itemDescription}> original price RS {price}</Text>
<Text style={styles.itemDescription}> price for 100 products RS {price}</Text>
</View>
</View>
</ImageBackground>
</View>
)
}
}
const styles = StyleSheet.create({
itemDescription: {
fontSize: 15,
color: "black",
},
productView: {
// borderRadius:30,
// backgroundColor:"red",
elevation: 2,
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 15,
paddingRight: 15,
height: 150,
width: "100%",
marginLeft: 15,
// marginRight: 20,
marginTop: 10,
// borderWidth: 0.14,
// borderRadius:10
// marginBottom:50,
// borderColor:"black"
}
})
import React, {Component} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import CustomCard from './CustomCard';
import { ScrollView } from 'react-native';
export default class ClearStock extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
return (
<View>
<Text>About Clearing Stock</Text>
{
this.state.product.map((data,index) => {
return(
<CustomCard products={data} key={index}></CustomCard>
// <Text>Hello</Text>
)
})
}
</View>
);
}
}
import React,{Component}来自'React';
从“react native”导入{View,Text,TouchableOpacity,StyleSheet};
从“./组件/连接”导入连接;
从“./Components/ClearStock”导入ClearStock;
从“./Components/NewProducts”导入新产品;
从“./组件/折扣”导入折扣;
从“./Components/CustomButton”导入CustomButton;
从“react native”导入{ScrollView};
//从“react native”导入{ScrollView};
导出默认类NewsFeed扩展组件{
状态={
已选择:“ClearStock”,
};
按钮单击(名称){
this.setState({selected:name});
}
render(){
返回(
this.buttonClick('ClearStock')}
iconName=“stumbleupon circle”>
清仓
this.button单击(“折扣”)}
iconName=“主页”>
折扣
this.buttonClick('NewProducts')}
iconName=“自由代码营”>
新产品
this.button单击('Connections')}
iconName=“主页”>
连接
{this.state.selected==='ClearStock'(
):this.state.selected==“折扣”(
):this.state.selected==='NewProducts'(
) : (
)}
);
}
}
styles=样式表.create({
B风格:{
marginLeft:40,
//背景颜色:'红色',
边界半径:10,
}
});
CustomCard.js
import React, {Component} from 'react';
import {View, Text, TouchableOpacity,StyleSheet} from 'react-native';
import Connections from './Components/Connections';
import ClearStock from './Components/ClearStock';
import NewProducts from './Components/NewProducts';
import Discounts from './Components/Discounts';
import CustomButton from './Components/CustomButton';
import { ScrollView } from 'react-native';
// import {ScrollView} from 'react-native';
export default class NewsFeed extends Component {
state = {
selected: 'ClearStock',
};
buttonClick(name) {
this.setState({selected: name});
}
render() {
return (
<View>
<View style={{flexDirection: 'row',borderWidth:5,backgroundColor:'#ffc687'}}>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('ClearStock')}
iconName="stumbleupon-circle">
Clear Stock
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Discounts')}
iconName="home" >
Discounts
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('NewProducts')}
iconName="free-code-camp">
New Products
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Connections')}
iconName="home">
Connections
</CustomButton>
</View>
<View>
{this.state.selected === 'ClearStock' ? (
<ClearStock />
) : this.state.selected === 'Discounts' ? (
<Discounts />
) : this.state.selected === 'NewProducts' ? (
<NewProducts />
) : (
<Connections />
)}
</View>
</View>
);
}
}
styles=StyleSheet.create({
btnStyle:{
marginLeft:40,
// backgroundColor:'red',
borderRadius:10,
}
});
import React, { Component } from 'react';
import {ImageBackground, View, TouchableOpacity, StyleSheet, Image, Text, ScrollView } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class CustomCard extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
const { name, quantity, price, category, tags, color, imageUrl } = this.props.products;
return (
<View >
<ImageBackground
style={styles.productView}
source={{ uri: "https://www.akfoconee.com/wp-content/uploads/2017/12/kids-martial-arts-landing-page-section-two-background-min-min.png" }}
>
<View style={{ flexDirection: 'row' }}>
<Icon name="bullhorn" size={30} />
<View style={{ marginLeft: 30, padding: 10, height: "100%", borderRadius: 30, borderWidth: 1, borderColor: "orange", width: "30%" }}>
<Image style={{ marginLeft: 10, height: "100%", width: 100, resizeMode: "contain" }} source={{ uri: imageUrl }} />
</View>
<View style={{ padding: 1, marginLeft: 10 }}>
<Text> We are offering FLASH SALE</Text>
<Text style={styles.itemDescription}>{name}</Text>
<Text style={styles.itemDescription}>{quantity}</Text>
<Text style={styles.itemDescription}> original price RS {price}</Text>
<Text style={styles.itemDescription}> price for 100 products RS {price}</Text>
</View>
</View>
</ImageBackground>
</View>
)
}
}
const styles = StyleSheet.create({
itemDescription: {
fontSize: 15,
color: "black",
},
productView: {
// borderRadius:30,
// backgroundColor:"red",
elevation: 2,
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 15,
paddingRight: 15,
height: 150,
width: "100%",
marginLeft: 15,
// marginRight: 20,
marginTop: 10,
// borderWidth: 0.14,
// borderRadius:10
// marginBottom:50,
// borderColor:"black"
}
})
import React, {Component} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import CustomCard from './CustomCard';
import { ScrollView } from 'react-native';
export default class ClearStock extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
return (
<View>
<Text>About Clearing Stock</Text>
{
this.state.product.map((data,index) => {
return(
<CustomCard products={data} key={index}></CustomCard>
// <Text>Hello</Text>
)
})
}
</View>
);
}
}
import React,{Component}来自'React';
从“react native”导入{ImageBackground,View,TouchableOpacity,StyleSheet,Image,Text,ScrollView};
从“反应本机矢量图标/FontAwesome”导入图标;
导出默认类CustomCard扩展组件{
状态={
产品:[
{
姓名:“马克杯”,
数量:2,
价格:199,
类别:“厨具”,
标签:[“杯子”、“厨房”、“餐具”],
颜色:“白色”,
图像URL:“https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
名称:“三星A50”,
数量:6,
价格:15000,
类别:“手机”,
标签:[“杯子”、“厨房”、“电话”],
颜色:“黑色”,
图像URL:“https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$”
},
{
名称:“诺基亚A50”,
数量:6,
价格:15000,
类别:“手机”,
标签:[“杯子”、“厨房”、“电话”],
颜色:“黑色”,
图像URL:“https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
名称:“QMobile A50”,
数量:6,
价格:15000,
类别:“手机”,
标签:[“杯子”、“厨房”、“电话”],
颜色:“黑色”,
图像URL:“https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render(){
const{name,quantity,price,category,tags,color,imageUrl}=this.props.products;
返回(
我们提供特卖
{name}
{数量}
原价{price}
100种产品的价格{price}
)
}
}
const styles=StyleSheet.create({
项目说明:{
尺寸:15,
颜色:“黑色”,
},
productView:{
//边界半径:30,
//背景颜色:“红色”,
标高:2,
paddingTop:15,
填充底部:15,
paddingLeft:15,
paddingRight:15,
身高:150,
宽度:“100%”,
marginLeft:15,
//marginRight:20,
玛金托普:10,
//边框宽度:0.14,
//边界半径:10
//marginBottom:50,
//边框颜色:“黑色”
}
})
ClearStock.js
import React, {Component} from 'react';
import {View, Text, TouchableOpacity,StyleSheet} from 'react-native';
import Connections from './Components/Connections';
import ClearStock from './Components/ClearStock';
import NewProducts from './Components/NewProducts';
import Discounts from './Components/Discounts';
import CustomButton from './Components/CustomButton';
import { ScrollView } from 'react-native';
// import {ScrollView} from 'react-native';
export default class NewsFeed extends Component {
state = {
selected: 'ClearStock',
};
buttonClick(name) {
this.setState({selected: name});
}
render() {
return (
<View>
<View style={{flexDirection: 'row',borderWidth:5,backgroundColor:'#ffc687'}}>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('ClearStock')}
iconName="stumbleupon-circle">
Clear Stock
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Discounts')}
iconName="home" >
Discounts
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('NewProducts')}
iconName="free-code-camp">
New Products
</CustomButton>
<CustomButton
style={styles.btnStyle}
onPress={() => this.buttonClick('Connections')}
iconName="home">
Connections
</CustomButton>
</View>
<View>
{this.state.selected === 'ClearStock' ? (
<ClearStock />
) : this.state.selected === 'Discounts' ? (
<Discounts />
) : this.state.selected === 'NewProducts' ? (
<NewProducts />
) : (
<Connections />
)}
</View>
</View>
);
}
}
styles=StyleSheet.create({
btnStyle:{
marginLeft:40,
// backgroundColor:'red',
borderRadius:10,
}
});
import React, { Component } from 'react';
import {ImageBackground, View, TouchableOpacity, StyleSheet, Image, Text, ScrollView } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class CustomCard extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
const { name, quantity, price, category, tags, color, imageUrl } = this.props.products;
return (
<View >
<ImageBackground
style={styles.productView}
source={{ uri: "https://www.akfoconee.com/wp-content/uploads/2017/12/kids-martial-arts-landing-page-section-two-background-min-min.png" }}
>
<View style={{ flexDirection: 'row' }}>
<Icon name="bullhorn" size={30} />
<View style={{ marginLeft: 30, padding: 10, height: "100%", borderRadius: 30, borderWidth: 1, borderColor: "orange", width: "30%" }}>
<Image style={{ marginLeft: 10, height: "100%", width: 100, resizeMode: "contain" }} source={{ uri: imageUrl }} />
</View>
<View style={{ padding: 1, marginLeft: 10 }}>
<Text> We are offering FLASH SALE</Text>
<Text style={styles.itemDescription}>{name}</Text>
<Text style={styles.itemDescription}>{quantity}</Text>
<Text style={styles.itemDescription}> original price RS {price}</Text>
<Text style={styles.itemDescription}> price for 100 products RS {price}</Text>
</View>
</View>
</ImageBackground>
</View>
)
}
}
const styles = StyleSheet.create({
itemDescription: {
fontSize: 15,
color: "black",
},
productView: {
// borderRadius:30,
// backgroundColor:"red",
elevation: 2,
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 15,
paddingRight: 15,
height: 150,
width: "100%",
marginLeft: 15,
// marginRight: 20,
marginTop: 10,
// borderWidth: 0.14,
// borderRadius:10
// marginBottom:50,
// borderColor:"black"
}
})
import React, {Component} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import CustomCard from './CustomCard';
import { ScrollView } from 'react-native';
export default class ClearStock extends Component {
state = {
product: [
{
name: "Mug",
quantity: 2,
price: 199,
category: "Kitchen ware",
tags: ["mug", "kitchen", "utensils"],
color: "White",
imageUrl: "https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
name: "Samsung A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$"
},
{
name: "Nokia A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://assets.mspimages.in/wp-content/uploads/2019/03/Nokia-X71-696x435.jpg"
},
{
name: "QMobile A50",
quantity: 6,
price: 15000,
category: "Mobile Phone",
tags: ["mug", "kitchen", "phone"],
color: "Black",
imageUrl: "https://www.whatmobile.com.pk/admin/images/Qmobile/NoirJ5b.jpg"
},
]
}
render() {
return (
<View>
<Text>About Clearing Stock</Text>
{
this.state.product.map((data,index) => {
return(
<CustomCard products={data} key={index}></CustomCard>
// <Text>Hello</Text>
)
})
}
</View>
);
}
}
import React,{Component}来自'React';
从“react native”导入{View,Text,TouchableOpacity};
从“/CustomCard”导入CustomCard;
从“react native”导入{ScrollView};
导出默认类ClearStock扩展组件{
状态={
产品:[
{
姓名:“马克杯”,
数量:2,
价格:199,
类别:“厨具”,
标签:[“杯子”、“厨房”、“餐具”],
颜色:“白色”,
图像URL:“https://images-na.ssl-images-amazon.com/images/I/61KB6fUhcSL._SL1500_.jpg"
},
{
名称:“三星A50”,
数量:6,
价格:15000,
类别:“手机”,
标签:[“杯子”、“厨房”、“电话”],
颜色:“黑色”,
图像URL:“https://johnlewis.scene7.com/is/image/JohnLewis/238087827?$rsp-pdp-port-1440$”
},
{
名称:“诺基亚A50”,
数量:6,
价格:15000,
类别:“手机”,
标签:[“杯子”、“厨房”、“电话”],