I have the following render function:
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text> Header
</Text>
</View>
<View style={styles.services}>
<Text>Services</Text>
</View>
<View style={styles.chart}>
<VictoryChart>
<VictoryLine
style={{
data: {stroke: "#c43a31"},
parent: {border: "1px solid #ccc"}
}}
data={[
{x: 1, y: 2},
{x: 2, y: 3},
{x: 3, y: 5},
{x: 4, y: 4},
{x: 5, y: 7}
]}
/>
</VictoryChart>
</View>
</View>
);
}
I have some sort of chart in the bottom section of page, But I cannot force the chart to fill the its parent, It kind of overflows from its dedicated section, How can I achieve this?(I tried to use flexWrap but it is no help !)
Here is the preview of what it looks like now:
And here is my style sheet for this simple design:
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
header: {
flex: 1,
backgroundColor: '#e7fe52'
},
services: {
flex: 4,
backgroundColor: '#20fe23'
},
chart: {
flex: 2,
flexWrap: 'wrap',
backgroundColor: '#4fccb0'
}
});
VictoryChart seems to have a default height of 300 and it doesn't adapt to its parent height. So, one way to solve this would be to remove the flex: 2 attribute from the chart style and add manually calculated dimensions. Something like this:
const chartHeight = Dimensions.get("window").height * 0.3;
const chartWidth = Dimensions.get("window").width;
<VictoryChart height={chartHeight} width={chartWidth} >
<VictoryLine
style={{
data: {stroke: "#c43a31"},
parent: {border: "1px solid #ccc"}
}}
data={[
{x: 1, y: 2},
{x: 2, y: 3},
{x: 3, y: 5},
{x: 4, y: 4},
{x: 5, y: 7}
]}
/>
</VictoryChart>
// styles
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
header: {
flex: 1,
backgroundColor: '#e7fe52'
},
services: {
flex: 4,
backgroundColor: '#20fe23'
},
chart: {
//remove flex from here
backgroundColor: '#4fccb0'
}
});
Although this is not perfect it works, but I would set a minimum height for the chart. I mean if the available space is too small, it won't look nice.
In this case you could wrap your screen inside a ScrollView.
each flex container is one flex try to divide your component into 1
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
header: {
flex: 0.15,
backgroundColor: '#e7fe52'
},
services: {
flex: 0.5,
backgroundColor: '#20fe23'
},
chart: {
flex: 0.35,
flexWrap: 'wrap',
backgroundColor: '#4fccb0'
}
});
0.15 + 0.5 + 0.35 = 1
Related
I have an echart with a serie type:'custom' and I have a rendering issues on the labels.
I return this
return {
type: 'group',
children: [
{
type: 'rect',
ignore: !rectNormal,
shape: rectNormal,
style: { stroke: '#707070' }
},
{
type: 'rect',
ignore: !rectText,
shape: rectText,
strokeLinejoin: "round",
stroke: 'trasparent',
strokeWidth: 0,
style: api.style({
fill: 'transparent',
fontWeight: bigText? 600 : 100,
fontSize: bigText? 15 : 10,
textStroke: '#707070',
strokeLinejoin: "round",
strokeLinecap: "round",
textStrokeWidth: 3,
text: text,
textFill: '#ffffff'
})
}
]
And it' rendered like this
As you can see the text stroke have problem in rendering the M letters and the strokeLinejoin and strokeLinecap did not solve the problem.
Do someone know how to fix this?
I solved it this way
{
type: 'rect',
ignore: !rectText,
shape: rectText,
strokeLinejoin: "round",
stroke: 'trasparent',
strokeWidth: 0,
style: api.style({
fill: 'transparent',
fontWeight: bigText? 600 : 100,
fontSize: bigText? 15 : 10,
textStroke: '#707070',
lineJoin: "bevel",
textStrokeWidth: 3,
text: text,
textFill: '#ffffff'
})
}
I'm trying to get results such as this in my MUI Button -
http://jsfiddle.net/bcGdJ/3160/
I ended up with this, but it seems that both before and after css selectors doesn't work.
import React from "react";
import Button from "#material-ui/core/Button";
import Notifications from "#material-ui/icons/Notifications";
import "./box.css";
const styles = {
color: 'purple',
backgroundColor: 'gray',
minWidth: '40px',
minHeight: '40px',
borderRadius: 1,
position: "relative",
"&:before,&:after": {
content: '',
position: "absolute",
bottom: 0,
left: 0,
borderColor: "transparent",
borderStyle: "solid"
},
"&:before": {
borderWidth: "8px",
borderLeftColor: "#efefef",
borderBottomColor: "#efefef",
},
"&:after": {
borderRadius: "3px",
borderWidth: "5px",
borderLeftColor: "#fff", /* color of the triangle */
borderBottomColor: "#fff" /* color of the triangle */
}
};
function CustomizedInputs(props) {
return (
<div id="container">
<Button color="primary" style={styles}>
<Notifications />
</Button>
</div>
);
}
export default CustomizedInputs;
```
https://codesandbox.io/s/72jyr75461
Any help would be appreciated
Your code is nice but you missed some simple points.
You need to use content: "''" instead of content: "".
You need to use :: instead of : for before and after.
cssRoot: {
color: theme.palette.getContrastText(purple[500]),
backgroundColor: purple[200],
minWidth: "40px",
minHeight: "40px",
borderRadius: 1,
position: "relative",
"&::before,&::after": {
content: "''",
position: "absolute",
bottom: 0,
left: 0,
borderColor: "transparent",
borderStyle: "solid"
},
"&::before": {
borderWidth: "8px",
borderLeftColor: "#efefef",
borderBottomColor: "#efefef"
},
"&::after": {
borderRadius: "3px",
borderWidth: "5px",
borderLeftColor: "#fffff" /* color of the triangle */,
borderBottomColor: "#fffff" /* color of the triangle */
}
}
https://codesandbox.io/s/541v247qlp
On react-native iOS, "react-native-linear-gradient": "^2.0.0".
After installing correctly this package with npm then using 'react-native link', i see a red border around my text but not any gradient with the example provided.
import LinearGradient from 'react-native-linear-gradient';
// Within your render function
<LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} style={styles.linearGradient}>
<Text style={styles.buttonText}>
Sign in with Facebook
</Text>
</LinearGradient>
// Later on in your styles..
var styles = StyleSheet.create({
linearGradient: {
flex: 1,
paddingLeft: 15,
paddingRight: 15,
borderRadius: 5
},
buttonText: {
fontSize: 18,
fontFamily: 'Gill Sans',
textAlign: 'center',
margin: 10,
color: '#ffffff',
backgroundColor: 'transparent',
},
});
Please check this out
https://alligator.io/react/gradient-border-react-native/
I have solved this problem from this blog.
Code Example :
<LinearGradient
colors={["#FFA500", "#C5121B"]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={{ borderRadius: 5 }}
>
<View style={styles.registerButtonStyle}>
<Text>Register</Text>
</View>
</LinearGradient>
registerButtonStyle: {
paddingLeft: 16,
paddingRight: 16,
paddingBottom: 7,
paddingTop: 7,
margin: 1,
backgroundColor: "white",
borderRadius: 5
},
Solved in my case with RN 0.41.2: run this command in the terminal 'react-native run-ios' for recompiling with xCode (necessary in general after a 'react-native link' command)
I'm creating a custom "Navigation bar" for my app and I need the following layout:
| ================================== |
| ICON TWO LINES TEXT |
| TWO LINES TEXT |
| ================================== |
The two <Text> fields should be at the center of the status bar and the icon on the right
That's how it looks like now:
Current layout
and in the inspector its how it looks
View inspector
as you can see the text is at the center of his space, but I want to be at the center of the entire component.
That's the code right now:
const styles = {
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#64619b',
height: 64,
paddingTop: 10,
},
title: {
color: 'white',
fontSize: 17,
},
belowTitle: {
color: 'white',
fontSize: 20,
fontWeight: 'bold',
},
backButton: {
width: 32,
height: 32,
alignSelf: 'center',
marginLeft: 16,
},
textContainer: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
};
class NavigatorHeader extends React.Component {
render() {
return <View style={[styles.container, this.props.style]}>
<TouchableOpacity onPress={this.onBackPress.bind(this)}>
<Icon name="ion|ios-arrow-back" size={32} color="white" style={styles.backButton} />
</TouchableOpacity>
<View style={styles.textContainer}>
<Text style={styles.title}>{this.props.title}</Text>
{this.props.belowTitle && <Text style={styles.belowTitle}>{this.props.belowTitle}</Text>}
</View>
</View>;
}
}
You could handle this by making it three views across. Put you button in the left, text in the center and then leave the right one empty. Then do "flex: 0.25" for the left and right then put "flex: 0.5" for the center. You can of course increase or decrease the two sides just make sure the center is whatever is left to get to 1.0
I have an optional feature for a chart that adds a renderer.text text object. When the chart is exported I would like this to be added only in that case. Below I have source code on how I have been accessing the renderer and the exporter. In the commented section Insert Here is where I was thinking it might go but I am unsure of the syntax. Thank you
myChart.renderer.text('Filtered', 5, 10)
.attr({rotation: 0})
.css({color: '#4572A7', fontSize: '8px', fontStyle:'italic'})
.add();
myChart.exportChart(null,
{chart:
{backgroundColor: '#FFFFFF', width: 972, height:480 /*Insert Here*/
}
}
);
You are right - there you should use load event to add extra text for exported image: http://jsfiddle.net/3bQne/88/
chart.exportChart(null, {
chart: {
backgroundColor: '#FFFFFF',
width: 972,
height: 480,
events: {
load: function () {
this.renderer.text('Filtered', 5, 10)
.attr({
rotation: 0
})
.css({
color: '#4572A7',
fontSize: '8px',
fontStyle: 'italic'
})
.add();
}
}
}
});