Good afternoon, I'm trying to make flatlist to display a number of objects from an API but for some reason, this flatlist seems not to work as I expected it to do, Wonder if anyone can find what's the issue here.
The flatlist was working properly before I import the API, because I made a custom set of data and it showed those without any issue but after I imported API like this flatlist has stopped working.
const [Accounts, setAccounts] = useState([]);
useEffect(() => {
const getDataList = async () => {
await axios
.get(
"API LINK" //I changed the API access link for security reasons but I can get log for response and Accounts in useState hook and it works properly!
)
.then((response) => {
//console.log(response.data, "loge response");
setAccounts(response.data);
})
.catch((error) => {
console.log(error, "loge error");
});
};
getDataList(); //we can put function out of the useEffect but you need to call one in order to run the function(getDataList) once in the code by useEffect.
}, []);
Flatlist code is below:
<FlatList
style={StyleSheet.container}
data={Accounts}
keyExtractor={(Accounts) => Accounts?.id}
renderItem={({ item }) => {
return (
<>
<View style={styles.container}>
<Text style={styles.items}>{item?.games}</Text>
<TouchableOpacity style={styles.price}>
<Text>{item?.price}</Text>
</TouchableOpacity>
</View>
</>
);
}}
></FlatList>
</>
I tried to get a log from Accounts and it shows all of the information that it gets from API but for some reason, without any errors, flatlist doesn't display any items.
This is a sample of the API data:
{
"id": 115,
"sellerId": 2,
"price": 105000,
"region": "2",
"isAvailable": true,
"plus": null,
"games": "Demon's Souls Digital Deluxe Edition PS5",
"view": 17,
"createdAt": "2021-02-26T11:17:10.000Z",
"sellers": {
"username": "ben"
}
},
{
"id": 116,
"sellerId": 3,
"price": 150000,
"region": "1",
"isAvailable": true,
"plus": true,
"games": "PES 2021,Assassin's Creed Valhalla ,WWE 2K20",
"view": 6,
"createdAt": "2021-02-26T11:17:11.000Z",
"sellers": {
"username": "moeindana"
}
In addition, these are the styling that currently I'm using:
const styles = StyleSheet.create({
container: {
borderRadius: 10,
borderWidth: 0.5,
borderColor: "black",
alignItems: "center",
maxWidth: "80%",
paddingTop: 20,
width: "90%",
backgroundColor: "gray",
marginLeft: 30,
marginTop: 26,
minHeight: 400,
paddingBottom: 100,
},
items: {
alignItems: "center",
maxWidth: "80%",
justifyContent: "center",
},
title: {
fontSize: 32,
},
price: {
fontSize: 15,
padding: 17,
paddingBottom: 20,
fontWeight: "bold",
borderRadius: 10,
borderColor: "black",
borderWidth: 0.5,
marginTop: 20,
top: 300,
position: "absolute",
},
}
Related
In data I have a am5.Picture object
icon = am5.Picture.new(root, {
height: 28,
src: src
});
The image fits on the text, is not inserted next to it
this doesn't work either
series.labels.template.set("text", "{icon} {name}") // return only name
Used Container
series.labels.values.forEach((label, index) => {
if (label.dataItem.dataContext.icon) {
let container = am5.Container.new(root, {
layout: root.horizontalLayout
})
container.children.push(label.dataItem.dataContext.icon)
container.children.push(
am5.Label.new(root, {
text: label.dataItem.dataContext.name,
fontSize: 10,
textAlign: "left",
centerY: am5.percent(50),
paddingLeft: 5,
})
)
label.children.clear()
label.children.push(container)
} else {
label.setAll({
fontSize: 10,
fontWeight: "300",
textAlign: "left",
maxWidth: 260,
oversizedBehavior: "wrap",
text: "{name}"
})
}
})
I succeeded in running the code provided by the site using react-native-maps-super-cluster.
However I cannot know how can I add my custom marker to the code.
How can I add my custom markers.
When I add my marker, it did not clustered.
The number of markers are exceed 1000+.
Dependencies are
"dependencies": {
"geolocation": "^0.2.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-geolocation-service": "^3.1.0",
"react-native-maps": "0.26.1",
"react-native-maps-super-cluster": "^1.6.0",
},
Bellows are current code.
import React, { Component } from 'react'
import {
Text,
View,
Image,
StyleSheet,
SafeAreaView,
TouchableOpacity,
} from 'react-native'
import { Marker, Callout } from 'react-native-maps'
import ClusteredMapView from 'react-native-maps-super-cluster'
import { generateRandomPoints, generateRandomPoint } from './generator'
const italyCenterLatitude = 37.521291,
italyCenterLongitude = 126.991733,
radius = 600000
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
pins: []
}
this.reload = this.reload.bind(this)
this.loadMore = this.loadMore.bind(this)
this.renderMarker = this.renderMarker.bind(this)
this.renderCluster = this.renderCluster.bind(this)
}
componentDidMount() {
this.reload()
}
reload = () => {
const pins = generateRandomPoints({ latitude: italyCenterLatitude, longitude: italyCenterLongitude }, radius, 50, this.state.pins.length)
this.setState({ pins: pins })
}
loadMore = () => {
const pins = generateRandomPoints({ latitude: italyCenterLatitude, longitude: italyCenterLongitude }, radius, 50, this.state.pins.length)
this.setState({ pins: this.state.pins.concat(pins) })
}
renderCluster = (cluster, onPress) => {
const pointCount = cluster.pointCount,
coordinate = cluster.coordinate,
clusterId = cluster.clusterId
return (
<Marker identifier={`cluster-${clusterId}`} coordinate={coordinate} onPress={onPress}>
<View style={styles.clusterContainer}>
<Text style={styles.clusterText}>
{pointCount}
</Text>
</View>
</Marker>
)
}
renderMarker = (pin) => {
return (
<Marker identifier={`pin-${pin.id}`} key={pin.id} coordinate={pin.location} />
)
}
render() {
return (
<SafeAreaView style={styles.container}>
{/* Cluster Map Example */}
<ClusteredMapView
style={{ flex: 1 }}
data={this.state.pins}
renderMarker={this.renderMarker}
renderCluster={this.renderCluster}
initialRegion={{ latitude: italyCenterLatitude, longitude: italyCenterLongitude, latitudeDelta: 12, longitudeDelta: 12 }}>
<Marker coordinate={{ latitude: 44.710968, longitude: 10.640131 }} pinColor={'#65bc46'} />
// Bellows are my marker. It do not clustered.
<Marker
coordinate={{ latitude: 37.5299448479299, longitude: 126.837746714377, }}
image={require('../gudu6/GuduIcon1w100.png')}
pinColor={'#65bc46'}
title=" 양천구 신월동 " description=" 228-1 번지" />
<Marker
coordinate={{ latitude: 37.58758812498327, longitude: 127.03790040097465, }}
image={require('../gudu6/GuduIcon1w100.png')}
pinColor={'#65bc46'}
title=" 동대문구 제기동 " description=" 1212 번지" />
<Marker
coordinate={{ latitude: 37.579331071917416, longitude: 127.04206659725423, }}
image={require('../gudu6/GuduIcon1w100.png')}
pinColor={'#65bc46'}
title=" 동대문구 제기동 " description=" 652-1 번지" />
</ClusteredMapView>
<View style={styles.controlBar}>
<TouchableOpacity
style={styles.button}
onPress={this.reload}>
<Text style={styles.text}>Reload</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={this.loadMore}>
<Text style={styles.text}>Load more</Text>
</TouchableOpacity>
</View>
<Image
resizeMode='contain'
source={require('./simbol.png')}
style={{ position: 'absolute', bottom: 26, right: 8, width: 64, height: 64 }} />
</SafeAreaView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#F5FCFF',
},
clusterContainer: {
width: 30,
height: 30,
padding: 6,
borderWidth: 1,
borderRadius: 15,
alignItems: 'center',
borderColor: '#65bc46',
justifyContent: 'center',
backgroundColor: 'white',
},
clusterText: {
fontSize: 13,
color: '#65bc46',
fontWeight: '500',
textAlign: 'center',
},
controlBar: {
top: 48,
left: 25,
right: 25,
height: 40,
borderRadius: 20,
position: 'absolute',
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 20,
backgroundColor: 'white',
justifyContent: 'space-between',
},
button: {
paddingVertical: 8,
paddingHorizontal: 20,
},
novaLabLogo: {
right: 8,
bottom: 8,
width: 64,
height: 64,
position: 'absolute',
},
text: {
fontSize: 16,
fontWeight: 'bold'
},
clusterContainer: {
width: 24,
height: 24,
borderWidth: 1,
borderRadius: 12,
alignItems: 'center',
borderColor: '#65bc46',
justifyContent: 'center',
backgroundColor: '#fff'
},
counterText: {
fontSize: 14,
color: '#65bc46',
fontWeight: '400'
},
calloutStyle: {
width: 64,
height: 64,
padding: 8,
borderRadius: 8,
borderColor: '#65bc46',
backgroundColor: 'white',
},
})
I think your issue is that you are defining each marker statically within your mapview component. The function you pass to the renderMarker prop will render a marker for each marker given to the data prop of the Mapview. This will allow the package to dynamically cluster your array of markers.
I tried to change the header style of the Datagrid component based on material-ui style guide. Datagrid body content is updated based on custom style but the header is not reflected the custom style changes.
the code snippet is below:
export const TableStyleProp = {
style: {
color: "#ff0000"
},
selectable: true,
headerStyle: {
color: "#ff0000"
},
bodyStyle: {}
};
const muiTheme = getMuiTheme({
table: {
backgroundColor: "#FF0000 !important"
},
thead: {
backgroundColor: "#b7cbfb"
},
tableHeader: {
borderColor: "#FF0000",
backgroundColor: "#FF0000"
},
tableHeaderColumn: {
textColor: "#FF0000",
height: 56,
spacing: 24
},
tableRow: {
hoverColor: "#FF0000",
stripeColor: "#FF0000",
selectedColor: "#FF0000",
textColor: "#FF00FF",
borderColor: "#FF0000",
height: 48
},
tableRowColumn: {
height: 48,
spacing: 24
}
});
<MuiThemeProvider muiTheme={muiTheme}>
This is described in the documentation: https://marmelab.com/admin-on-rest/List.html#custom-grid-style
I'm trying to simultaneously restrict the values of my animation (using clamp as well as interpolate) but also get the values out of the interpolation so I can use them. Specifically because I want to update a piece of state with them and create an observable from that. I just can't figure out how to extract the 'real' value out of the AnimatedValue that is produced by the interpolation (in this case state.panValue). I've tried
this.state.panValue.value
and
this.state.panValue._value
and they come back as undefined. If anyone could help me out would be amazing!
EDIT: I'd also be really happy to just have the
this.state.pan.x
variable updated within the limits so I can skip the whole updating the state variable 'panValue' thing. A nice guy on Facebook suggested that I could implement this limit somehow inside the onPanResponderMove by switching the variable to a function or something but I've tried several things and all I get are errors, I guess because I don't really know how to 'safely' amend these animated values.
onPanResponderMove: Animated.event([
null,
{ dx: this.state.pan.x },
]),
Original Code:
import React, { Component } from 'react';
import {
View,
Animated,
PanResponder,
Text,
} from 'react-native';
import styles from './styles';
class ClockInSwitch extends Component {
constructor(props) {
super(props);
this.state = {
pan: new Animated.ValueXY(),
panValue: 0,
};
}
componentWillMount() {
this._animatedValueX = 0;
this._animatedValueY = 0;
this.state.pan.x.addListener((value) => {
this._animatedValueX = value.value;
this.setState({
panValue: this.state.pan.x.interpolate({
inputRange: [-30, 0, 120,],
outputRange: [-10, 0, 120,],
extrapolate: 'clamp',
}),
});
});
this._panResponder = PanResponder.create({
// Ask to be the responder:
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) => {
this.state.pan.setOffset({
x: this._animatedValueX,
});
this.state.pan.setValue({ x: 0, y: 0 });
},
onPanResponderMove: Animated.event([
null,
{ dx: this.state.pan.x },
]),
onPanResponderTerminationRequest: (evt, gestureState) => true,
onPanResponderRelease: (evt, gestureState) => {
this.state.pan.flattenOffset();
Animated.timing(this.state.pan, {
toValue: 0,
duration: 500,
}).start();
},
onPanResponderTerminate: (evt, gestureState) => {
},
onShouldBlockNativeResponder: (evt, gestureState) => {
return true;
},
});
}
componentWillUnMount() {
this.state.pan.x.removeAllListeners();
}
render() {
const animatedStyle = {
transform: [{
translateX: this.state.panValue,
},
],
};
return (
<View>
<Text>{this.state.pan.x._value}</Text>
<View style={styles.buttonStyle}>
<Animated.View
style={[styles.sliderButtonStyle, animatedStyle]}
{...this._panResponder.panHandlers}
/>
</View>
</View>
);
}
}
export default ClockInSwitch;
I think this is what you're looking for. I'm using exponent so your declaration for vector icons would probably need to be changed. Cheers!
/**
* #providesModule ClockInSwitch
* #flow
*/
import React, {Component} from 'react';
import {View, Animated, StyleSheet, PanResponder, Text} from 'react-native';
import {FontAwesome} from '#exponent/vector-icons';
export class ClockInSwitch extends Component {
constructor(props) {
super(props);
this.state = {
pan: new Animated.ValueXY(),
panValue: 0
};
}
componentWillMount() {
this._panResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderGrant: (e, gestureState) => {
this
.state
.pan
.setValue({x: 0, y: 0});
},
//here's where you can check, constrain and store values
onPanResponderMove: (evt, gestureState) => {
// 300 is the width of the red container (will leave it to you to calculate this
// dynamically) 100 is the width of the button (90) plus the 5px margin on
// either side of it (10px total)
var newXVal = (gestureState.dx < 300 - 100)
? gestureState.dx
: 300 - 100;
this
.state
.pan
.x
.setValue(newXVal);
//set this state for display
this.setState({panValue: newXVal});
},
onPanResponderRelease: (e, {vx, vy}) => {
this
.state
.pan
.flattenOffset();
Animated
.spring(this.state.pan, {
toValue: 0,
duration: 400,
overshootClamping: true
})
.start();
this.setState({panValue: 0});
}
});
}
componentWillUnMount() {
this
.state
.pan
.x
.removeAllListeners();
}
render() {
//decouple the value from the state object
let {pan} = this.state;
let [translateX,
translateY] = [pan.x, pan.y];
let translateStyle = {
transform: [{
translateX
}, {
translateY
}]
};
return (
<View>
<Text style={styles.leftText}>Power Button Demo</Text>
<View style={styles.buttonStyle}>
<Animated.View
style={[styles.sliderButtonStyle, translateStyle]}
{...this._panResponder.panHandlers}>
<FontAwesome
name="power-off"
color="#EA2E49"
style={{
alignSelf: "center",
marginHorizontal: 10
}}
size={36}/>
</Animated.View>
</View>
<Text style={styles.rightText}>{this.state.panValue}: x value</Text>
</View>
);
}
}
export default ClockInSwitch;
const styles = StyleSheet.create({
sliderButtonStyle: {
borderColor: '#FCFFF5',
borderStyle: 'solid',
borderWidth: .5,
backgroundColor: '#FCFFF5',
borderRadius: 45,
height: 90,
width: 90,
justifyContent: 'center',
textAlign: 'center',
marginHorizontal: 5,
shadowColor: '#333745',
shadowOffset: {
width: 2,
height: 2
},
shadowOpacity: .6,
shadowRadius: 5
},
buttonStyle: {
borderColor: '#FCFFF500',
backgroundColor: '#DAEDE255',
borderStyle: 'solid',
borderWidth: 1,
height: 100,
width: 300,
justifyContent: 'center',
borderRadius: 50,
margin: 5,
flexDirection: 'column'
},
rightText: {
justifyContent: 'center',
textAlign: 'right',
fontWeight: '100',
marginHorizontal:15,
fontSize: 20,
color: '#FCFFF5',
marginVertical:25,
flexDirection: 'column'
},
leftText: {
justifyContent: 'center',
textAlign: 'left',
fontWeight: '100',
marginHorizontal:15,
fontSize: 24,
color: '#FCFFF5',
marginVertical:25,
flexDirection: 'column'
}
});
Keno spreadsheets are new and the documentation is very scarce.
I'm trying to do something relatively simple.
I have a spreadsheet with stylized headers like this:
this.sheetsHeader = [
{
name: "ProductsEntry",
rows: [
{
height: 15,
cells: [
{
value: "Name",
bold: "true",
background: "#00435e",
textAlign: "center",
color: "white",
fontSize: 14,
}, {
value: "Type",
bold: "true",
background: "#00435e",
textAlign: "center",
color: "white",
fontSize: 14,
},
{
value: "Currency",
bold: "true",
background: "#00435e",
textAlign: "center",
color: "white",
fontSize: 14,
},
{
value: "Rate",
bold: "true",
background: "#00435e",
textAlign: "center",
color: "white",
fontSize: 14
},
{
value: "StartDate",
bold: "true",
background: "#00435e",
textAlign: "center",
color: "white",
fontSize: 14,
}
]
}
],
columns: [
{ width: 200 },
{ width: 200 },
{ width: 90 },
{ width: 90 },
{ width: 110 }
]
}
];
and that gets initialized the normal way:
$("#spreadsheet").kendoSpreadsheet({
toolbar: false,
sheetsbar: false,
sheets: that.sheetsHeader
});
Then later I have an event that clears the spreadsheet but I want to leave the headers intact.
If I do this:
var sheet = spreadsheet.activeSheet();
sheet.range(kendo.spreadsheet.SHEETREF).clear();
It wipes out the headers and leaves the sheet entirely empty.
I tried re-adding the headers in many different ways but nothing worked for me.
Aftear clearing the spreadsheet I tried:
sheet.fromJSON(that.sheetsHeader[0].rows);
I also tried deleting the sheet and re-adding it:
spreadsheet.removeSheet(0);
spreadsheet.insertSheet(that.sheetsHeader);
Nothing really worked so far and there's no documentation for this sort of scenario. Any ideas?
This did it:
sheet.fromJSON(that.sheetsHeader[0]);
I really wish they provided some documentation though. It wasn't very intuitive.