我的技能很基础,而且我是React native的新手,我想做的就是将帖子限制在12个,并且当用户滚动时自动加载更多帖子。
我的代码:
export default class Posts extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,};}
componentDidMount() {
return fetch(ConfigApp.URL+'json/data_posts.php')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataPosts: responseJson
}, function() {
});
})
.catch((error) => {
});}
render() {
return (
<FlatList
data={ this.state.dataPosts }
numColumns={2}
renderItem={({item}) =>
<TouchableOpacity activeOpacity={1} style={{flex: 1}}>
<View style={{margin: 5, marginLeft: 4}}>
<ImageBackground source={{uri: ConfigApp.IMAGESFOLDER+item.post_image}}>
<LinearGradient colors={['rgba(0,0,0,0.3)', 'rgba(0,0,0,0.8)']}>
<Text numberOfLines={2}>{item.post_title}</Text>
</LinearGradient>
</ImageBackground>
</View>
</TouchableOpacity>
}
keyExtractor={(item, index) => index}
/> …Run Code Online (Sandbox Code Playgroud) 我想在样式表中创建通用变量颜色,我按如下所示创建了它,但它不起作用。
'use strict';
import {Dimensions} from "react-native";
var React = require('react-native');
var { StyleSheet } = React;
var { PrimaryColor } = "#DDDDDD";
module.exports = StyleSheet.create({
title_post:{
padding: 20,
color: PrimaryColor
},
button_share:{
backgroundColor: PrimaryColor
}
Run Code Online (Sandbox Code Playgroud) 我的本地反应技巧是基本的,我想创建一个基本的倒计时,当我点击播放倒计时开始时,就像这个例子:
我的代码:
render() {
return (
<Grid>
<Row>
<Col style={styles.col_exercise}>
<Image source={require('../../assets/images/done.png')} resizeMode="contain" style={styles.icon_videoexercise} />
<Text style={styles.titlecol_exercise}>Done</Text>
</Col>
<Col style={styles.col_exercise}>
<View style={{borderWidth: 2, borderColor: '#f39c12', borderRadius: 50, height: 100, width: 100,alignItems: 'center',
justifyContent: 'center'}}>
<Text style={{fontSize: 18, color: '#000'}}>
00:30
</Text>
</View>
</Col>
<Col style={styles.col_exercise}>
<Image source={require('../../assets/images/play.png')} resizeMode="contain" style={styles.icon_videoexercise} />
<Text style={styles.titlecol_exercise}>Play</Text>
</Col>
</Row>
</Grid>
);
}
Run Code Online (Sandbox Code Playgroud) 我想要得到的是选择“质量”的“url”值是 hd720
成分
componentDidMount() {
return fetch('https://you-link.herokuapp.com/?url=https://www.youtube.com/watch?v=YGCLs9Bt_KY')
.then((响应) => response.json())
.then((responseJson) => {
this.setState({
isLoading: 假,
数据源:responseJson,
视频网址:responseJson[0].url
}, 功能() {
});
})
.catch((错误) => {
控制台错误(错误);
});
}
Json 调用
链接