0
次のコードは、乱数を含む10個の正方形の行を生成します。私は何とか10行10列のグリッドにしようとしていますが、私はここで立ち往生しています。私は行の列を10に制限したいと思います。したがって、varの制限が40の場合、4行×10列が作成されます。 60は6行×10列などを作成します。リアクションネイティブ - グリッドを作成する
import React, { Component } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { connect } from 'react-redux';
import { Decrease, Increase, GetScore } from '../actions';
import { CardSection, Square } from './common';
class TableGenerator extends Component {
clickable(sq) {
this.props.Decrease(sq);
console.log(this.props.score);
}
generateRandom() {
// Random number generator
function* rand() {
while (true) {
yield Math.floor(Math.random() * 100) + 1;
}
}
const it = rand();
const nums = [];
const limit = 10;
for (let i = 0; i < limit; i++) {
nums.push(it.next().value);
}
return nums.map((sq, i) =>
<TouchableOpacity
key={i}
onPress={() => this.clickable(sq)}
>
<Square style={{ height: 30, width: 30 }}>
{nums[i]}
</Square>
</TouchableOpacity>
);
}
render() {
return (
<View>
<CardSection style={{ justifyContent: 'center' }}>
{this.generateRandom()}
</CardSection>
<CardSection>
<Text>Current Score: </Text>
<Text>{this.props.score}</Text>
</CardSection>
</View>
);
}
}
const mapStateToProps = state => {
return {
score: state.scoreReducer
};
};
export default connect(mapStateToProps, { Decrease, Increase, GetScore })(TableGenerator);
私は単に外枠を使って幅を制限し、余分な四角を次の行に押し付けます。 –
ありがとう。それと指定されたflexWrapを実行しましたか? – Wasteland
が回答を掲載しました。私はflexWrapを使わなかった。それは大きな違いではありません。 –