I'm trying to figure out how to customize the kepler.gl's mapbox style. I want to make the mapbox component fill the screen width and height.
I've already tried updating it using the dispatcher with no success:
this.props.dispatch(loadCustomMapStyle({inputStyle: {url: 'mapbox://styles/mapbox/navigation-guidance-day-v4', id: 'some-id', style: {width: '100%', height: '100%'}}}));
this.props.dispatch(addCustomMapStyle());
I also tried using the styled-components ThemeProvider:
<ThemeProvider theme={{width: '100%', height:'100%'}}>
<KeplerGl
id="foo"
mapboxApiAccessToken={'API_KEY'}
store={store}
/>
</ThemeProvider>
Any help would be greatly appreciated!
The KeplerGl component takes in width and height props (documentation here). To change these with the dimensions of a div, you can use AutoSizer. For example, for the KeplerGl component to fill the screen you could wrap it in a div that is fullscreen as follows:
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
...
<div style={{position: "absolute", width: "100%", height: "100%"}}>
<AutoSizer>
{({height, width}) => (
<KeplerGl
mapboxApiAccessToken={MAPBOX_TOKEN}
id="map"
width={width}
height={height}
/>
)}
</AutoSizer>
</div>
Related
I have a button in my app that needs to be a perfect rectangle, but with no styling attached to it, there's a tiny default border-radius to it. How can I resolve this?
<Button
title="Next"
onPress={() => // Next stuff}
buttonStyle={{
backgroundColor: "#000000",
width: 'auto',
}}
/>
I am trying to create shape of two circles overlapping on each other and i have done it successfully just overlapping part is showing background image instead of image which is set inside circles and quite new in react-native-svg area so please help me. Here is my code:
<ImageBackground source={require('../assets/images/20.png')} style={styles.background}>
<Svg height={height} width="100%">
<Defs>
<ClipPath id="clip">
<Circle cx="320" cy="230" r="250" />
<Circle cx="80" cy="150" r="180" />
</ClipPath>
</Defs>
<SvgImg
href={require('../assets/images/18.jpg')}
width={500}
height={500}
preserveAspectRatio="xMidYMid slice"
clipPath="url(#clip)"
/>
</Svg>
</ImageBackground>
const styles = StyleSheet.create({
background: {
width: 'auto',
height: '100%',
},
})
This is a common problem in ImageBackground
Because style needs to be defined for the internal image as well
try set imageStyle
<ImageBackground
imageStyle={{
resizeMode: 'contain',//or try anohter style
overflow: 'visible',
}}
>
We have a situation where on a screen there are multiple View components are present. And each component has some progress bar related stuff.
But when the user taps on any View, we want to expand it to the full screen and we are doing it by applying a new style,
fullscr: {
top: 0,
left: 0,
height: "100%",
width: 100%,
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
}
But the View is not expanding above Header and Footer of native base. It is expanding rest of the view but not Header and Footer.
I tried zIndex and elevation option but no luck. How can I expand a view to fill the entire screen?
You can conditionally hide the footer and header of native-base, that way in the Container component of native-base you have your view inside Content.
<Container>
{condition ? <Fragment> :<Header/>}
<Content>
{{Your main view goes here}}
</Content>
{condition ? <Fragment> :<Footer/>}
</Container>
(Note: I'm using Expo for this app)
I'm attempting to render a FlatList that displays a list of printers. Here's the code:
<FlatList
data={printers}
keyExtractor={printer => printer.id}
renderItem={({ item }) => {
return (
<Printer
printerTitle={item.name}
selected={item.selected}
last={item === last(printers)}
/>
);
}}
/>
Here's the code for the <Printer /> component:
const Printer = props => {
const { last, printerTitle, selected } = props;
return (
<View style={[styles.container, last ? styles.lastContainer : null]}>
<View style={styles.innerContainer}>
<View style={styles.leftContainter}>
{selected ? (
<Image source={selected ? Images.checkedCircle : null} />
) : null}
</View>
<View style={styles.printerDetails}>
<Text style={styles.printerTitle}>{printerTitle}</Text>
</View>
</View>
</View>
);
};
...
export default Printer;
I can't seem to get the <Printer /> component to render. I have tried including a similar custom component (that has worked in a FlatList in another part of the app) in the renderItem prop, and it doesn't work either.
However, when I replace the <Printer /> component with <Text>{item.name}</Text> component, the printer name renders like I would expect it to.
Has anyone run into this issue before, or does anyone have a solution?
In my case, where I'm rendering a custom component for each item in the list, it wasn't rendering because I accidentally had {} surrounding the return part of the renderItem prop instead of ().
Changing:
<FlatList
data={array}
renderItem={({item, index}) => { <CustomItemComponent /> }}
/>
to this:
<FlatList
data={array}
renderItem={({item, index}) => ( <CustomItemComponent /> )}
/>
Solved my issues.
I suspect there are two issues at hand: one is that your FlatList is not filling the screen (namely its parent view) and the other is that your Printer component is not being sized correctly.
For the first issue, put a style with { flex: 1 } on your FlatList. This way it will fill its parent view.
For the second issue, try adding { borderColor: 'red', borderWidth: 1 } to your Printer components, just so that you can more easily see where they're being rendered. If they seem like they have no width, make sure you haven't overridden alignSelf on the Printer component's root view. If they seem like they have no height, add height: 100 temporarily just so you can see what the contents of the Printer components look like.
Within your Printer component, make sure to specify the width and height of your image on the Image component like { width: 40, height: 30 } or whatever the dimensions of your image is in logical pixels.
I have same problem.
Resolve with adding width to FlatList
render() {
const dimensions = Dimensions.get('window');
const screenWidth = dimensions.width;
return(
<FlatList
style={{
flex: 1,
width: screenWidth,
}}
... some code here
/>
)
}
You can't use the keyExtractor in this way, make this function like below. It might solve your problem.
_keyExtractor = (item, index) => index;
If you update your question with you printer component code we can help you better.
In my case I accidentally made it a pair tag: <FlatList></FlatList>, which for some reason breaks rendering of list items.
in my case Container was not having width of 100%:
const Container = styled.View`
border: 1px solid #ececec;
margin-top: 43px;
padding-top: 36px
padding-bottom: 112px;
width: 100%;
`;
const StyledFlatList = styled(
FlatList as new () => FlatList<SimilarRewards_viewer['merchants']['edges'][0]>
)`
width: 100%;
height: 150px;
flex: 1;
padding-left: 15px;
padding-right: 15px;
`;
In the iOS version of my react native app built with NativeBase, everything is too skinny, unless a specific width is given. See images below. I have given the header and footer a width of 100% so it is fine, but I haven't done that for the inputs and they are too skinny. The header and footer are that skinny when not given a width too.
code:
import React from 'react'
import {
Container,
Header,
Form,
Item,
Input,
Label,
Content,
Footer,
FooterTab,
Button,
Left,
Right,
Body
} from 'native-base'
import { Text, Image } from 'react-native'
export const Volcalc = () => {
return (
<Container style={styles.container}>
<Header style={styles.header}>
<Left>
<Image resizeMode={Image.resizeMode.contain} style={styles.thumbnail} source={require('./img/logo_red_nowords.png')} />
</Left>
<Body>
</Body>
<Right />
</Header>
<Content>
<Form>
<Item stackedLabel bordered >
<Label>height</Label>
<Input />
</Item>
<Item stackedLabel >
<Label>width</Label>
<Input />
</Item>
</Form>
</Content>
<Footer >
<FooterTab style={styles.footer}>
<Button full>
<Text>Footer 1</Text>
</Button>
</FooterTab>
</Footer>
</Container>
)
}
const $mainColor = '#00d1b2'
const styles = {
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: $mainColor
},
header: {
width: '100%',
backgroundColor: $mainColor
},
footer: {
width: '100%',
backgroundColor: $mainColor
},
thumbnail: {
width: 35,
height: 35
}
}
I'm pretty sure I'm supposed to be able to add inputs and header, without specifying width, and it should take up the full width like Android does when not specifying. What could be wrong with my project that is causing this?
width: '100%' is supported in react native, it will take 100% of its parent width.
I think your problem is the the justifyContent:'center' and alignItems:'center' in the styles.container, they are causing all elements to be in the center of the component. You can try adding a distinctive background color to your Content component to see where it is and how much width it has.
Try adding this style:
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: $mainColor,
flexDirection: 'row' // <--- Add this line
}
Apart from above suggestion, you can use "Toggle Inspector" to get the style attributes. But I also found react native apps during development sometimes gets stuck in previous states. Try to uninstall and reinstall it.
Try using Dimensions.
import { Dimensions } from 'react-native';
var {width} = Dimension.get('window');
then you can use like
<Form style={{width:width}}>