如果没有 ScrollView,本机视图是否无法滚动
Does react-native view not able to scroll without ScrollView
这是本教程的 link(https://medium.com/react-native-development/how-to-use-the-flatlist-component-react-native-basics-92c482816fe6),我从这里开始学习 react-native。
除了视图不滚动外一切正常
import React, { Component } from 'react';
import { FlatList, Text, View } from 'react-native';
import { List, ListItem } from "react-native-elements";
type Props = {}
export default class FlatListDemo extends Component<Props> {
constructor(props) {
super(props);
this.state = {
loading: false,
data: [],
page: 1,
seed: 1,
error: null,
refreshing: false,
};
}
componentDidMount() {
this.makeRemoteRequest();
}
makeRemoteRequest = () => {
const { page, seed } = this.state;
const url = `https://randomuser.me/api/?seed=${seed}&page=${page}&results=20`;
this.setState({
loading: true
});
fetch(url)
.then(res => res.json())
.then(res => {
this.setState({
data: page === 1 ? res.results : [...this.state.data, ...res.results],
error: res.error || null,
loading: false,
refreshing: false
})
})
.catch(error =>
this.setState({
error,
loading: false
})
)
};
renderSeparator = () => {
return (
<View
style={{
height: 1,
width: "86%",
backgroundColor: "#CED0CE",
marginLeft: "14%"
}}
>
</View>
)
};
render() {
return (
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<ListItem
roundAvatar
title={`${item.name.first} ${item.name.last}`}
subtitle={item.email}
avatar={{ uri: item.picture.thumbnail }}
containerStyle={{ borderBottomWidth: 0 }}
/>
)}
ItemSeparatorComponent={this.renderSeparator}
onEndReachedThreshold={50}
/> )
}}
是否必须使用 ScrollView 才能滚动 react-native 视图,或者我们可以做到
使用任何 CSS 或其他东西
当我尝试 运行 此给定 link 中的此代码时: https://snack.expo.io/rkOsCaiD7 找到解决方案时,我发现滚动视图与上述代码一起工作正常。只需尝试重新加载并 运行 它在本机反应中,我认为它可能会解决您的问题。
这是本教程的 link(https://medium.com/react-native-development/how-to-use-the-flatlist-component-react-native-basics-92c482816fe6),我从这里开始学习 react-native。 除了视图不滚动外一切正常
import React, { Component } from 'react';
import { FlatList, Text, View } from 'react-native';
import { List, ListItem } from "react-native-elements";
type Props = {}
export default class FlatListDemo extends Component<Props> {
constructor(props) {
super(props);
this.state = {
loading: false,
data: [],
page: 1,
seed: 1,
error: null,
refreshing: false,
};
}
componentDidMount() {
this.makeRemoteRequest();
}
makeRemoteRequest = () => {
const { page, seed } = this.state;
const url = `https://randomuser.me/api/?seed=${seed}&page=${page}&results=20`;
this.setState({
loading: true
});
fetch(url)
.then(res => res.json())
.then(res => {
this.setState({
data: page === 1 ? res.results : [...this.state.data, ...res.results],
error: res.error || null,
loading: false,
refreshing: false
})
})
.catch(error =>
this.setState({
error,
loading: false
})
)
};
renderSeparator = () => {
return (
<View
style={{
height: 1,
width: "86%",
backgroundColor: "#CED0CE",
marginLeft: "14%"
}}
>
</View>
)
};
render() {
return (
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<ListItem
roundAvatar
title={`${item.name.first} ${item.name.last}`}
subtitle={item.email}
avatar={{ uri: item.picture.thumbnail }}
containerStyle={{ borderBottomWidth: 0 }}
/>
)}
ItemSeparatorComponent={this.renderSeparator}
onEndReachedThreshold={50}
/> )
}}
是否必须使用 ScrollView 才能滚动 react-native 视图,或者我们可以做到 使用任何 CSS 或其他东西
当我尝试 运行 此给定 link 中的此代码时: https://snack.expo.io/rkOsCaiD7 找到解决方案时,我发现滚动视图与上述代码一起工作正常。只需尝试重新加载并 运行 它在本机反应中,我认为它可能会解决您的问题。