This commit is contained in:
Flummi 2020-01-21 19:08:20 +01:00
parent 98b43ea729
commit def4c4af8a
2 changed files with 24 additions and 11 deletions

View File

@ -30,7 +30,6 @@ const AppNavigator = createBottomTabNavigator({
defaultNavigationOptions: ({ navigation }) => ({ defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => { tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state; const { routeName } = navigation.state;
let IconComponent = Ionicons;
let iconName; let iconName;
switch(routeName) { switch(routeName) {
case "Home": case "Home":
@ -46,7 +45,7 @@ const AppNavigator = createBottomTabNavigator({
iconName = "ios-settings"; iconName = "ios-settings";
break; break;
} }
return <IconComponent name={iconName} size={25} color={tintColor} />; return <Ionicons name={iconName} size={25} color={tintColor} />;
}, },
}), }),
}); });

View File

@ -7,34 +7,47 @@ import { Text, View, TouchableOpacity, FlatList, Image } from "react-native";
export default class HomeScreen extends React.Component { export default class HomeScreen extends React.Component {
state = { state = {
dataSource: [], dataSource: [],
debug: "deeeebug" columns: 1,
debug: "0.00px"
}; };
handleScroll = e => { handleScroll = e => {
const el = e.nativeEvent; const el = e.nativeEvent;
return;
this.setState({ this.setState({
debug: `${el.contentOffset.y.toFixed(2)}px` debug: `${el.contentOffset.y.toFixed(2)}px`
}); });
}; };
handleLayout = e => { handleLayout = async e => {
console.log(e.nativeEvent.layout); console.log(e.nativeEvent.layout);
};
async componentDidMount() { let h = e.nativeEvent.layout.height;
const res = await (await fetch("https://dev.f0ck.me/api/p?eps=54")).json(); let w = e.nativeEvent.layout.width;
let columns = ~~(w / 128);
let rows = ~~(h / 128);
let eps = 200;//columns * rows;
const res = await (await fetch(`https://dev.f0ck.me/api/p?eps=${eps}`)).json();
const items = res.items.map(e => ({ const items = res.items.map(e => ({
id: e.id, id: e.id,
src: `https://f0ck.me/t/${e.id}.png` src: `https://f0ck.me/t/${e.id}.png`
})); }));
this.setState({ this.setState({
dataSource: items dataSource: items,
columns: columns,
debug: `c: ${columns} r: ${rows} eps: ${eps}`
}); });
};
async componentDidMount() {
return true; // lul
} }
render() { render() {
return ( return (
<View style={{ flex: 1, backgroundColor: theme.background }}> <View style={{ flex: 1, backgroundColor: theme.background }}>
<Image source={{ uri: theme.logo }} style={{ width: 112, height: 28, marginTop: 16 }} /> <Image source={{ uri: theme.logo }} style={{ width: 112, height: 28, marginTop: 8 }} />
<Text style={{ color: "#fff", fontWeight: "bold", textAlign: "right" }}>{this.state.debug}</Text> <Text style={{ color: "#fff", fontWeight: "bold", textAlign: "right" }}>{this.state.debug}</Text>
<FlatList <FlatList
@ -42,13 +55,14 @@ export default class HomeScreen extends React.Component {
onScroll={this.handleScroll} onScroll={this.handleScroll}
onLayout={this.handleLayout} onLayout={this.handleLayout}
renderItem={({ item }) => ( renderItem={({ item }) => (
<View style={{ flex: 1, flexDirection: "column", margin: 1 }}> <View style={{ flex: 1, flexDirection: "column", margin: 5 }}>
<TouchableOpacity key={item.id} style={{ flex: 1 }} > <TouchableOpacity key={item.id} style={{ flex: 1 }} >
<Image style={{ height: 128, width: 128 }} source={{ uri: item.src }} /> <Image style={{ height: 128, width: 128 }} source={{ uri: item.src }} />
</TouchableOpacity> </TouchableOpacity>
</View> </View>
)} )}
numColumns={4} key = {this.state.columns}
numColumns={this.state.columns}
keyExtractor={(item, index) => index.toString()} keyExtractor={(item, index) => index.toString()}
/> />
</View> </View>