*Y-axis labels are reformatted value/60 *
Y-axis Max point is at 170 which is going out of graph.
Graph height is not adjusting according to the highest point of the Y-axis value.Also plotted graph for values going upto 200 above which is plotted correctly in range.
<View
style={{
height: 250,
paddingVertical: 10,
flexDirection: 'row',
}}>
<YAxis
data={props.data}
yAccessor={({item}) => item?.sleep_n1_time}
style={{marginBottom: xAxisHeight, width: 40, marginRight: 5}}
contentInset={verticalContentInset}
svg={axesSvg}
formatLabel={(value, idx) => {
if (props.data.length > 50) {
return idx % 5 === 0 ? formatTime(value) : '';
} else if (props.data.length > 20) {
return idx % 2 === 0 ? formatTime(value) : '';
} else {
return formatTime(value);
}
}}
/>
<View style={{flex: 1, marginRight: 10}}>
<StackedAreaChart
style={{height: 200, paddingVertical: 16}}
data={props.data}
keys={keys}
contentInset={{...horizontalContentInset, ...verticalContentInset}}
colors={colors}
curve={shape.curveNatural}
showGrid={false}
/>
<XAxis
style={{height: xAxisHeight}}
data={props.data}
formatLabel={(value, index) => {
if (props.data.length > 50) {
return index % 5 === 0 ? props.data[index]?.time : '';
} else if (props.data.length > 20) {
return index % 2 === 0 ? props.data[index]?.time : '';
} else {
return props.data[index]?.time;
}
}}
contentInset={horizontalContentInset}
svg={axesXSvg}
/>
</View>
</View>
Related
I want to integrate sectiolist view with its row item horizintal manner 1 to 30 partition and those items should be fix any resolution device it should not scroll refer my image for that
As you can see above image 30 is cutting so my requirement is 1 to 30 should fit in every mobile device without scroll and cut so any idea is it possible or how can i achieve this ?
Refer my code
const renderItemView = (item) => {
let colorValue = '';
switch (item.level) {
case 0:
colorValue = '#CCD4DF'
break;
case 1:
colorValue = '#47EF4E'
break;
case 2:
colorValue = '#F7C133'
break;
case 3:
colorValue = '#E68E92'
break;
case 4:
colorValue = '#ED271F'
break;
default:
break;
}
return (
<View style={{ borderWidth: 1, margin: 0.5, padding: 1, backgroundColor: colorValue}}>
<Text style={{ fontSize: 8 }}>{item.day}</Text>
</View>
)
}
return (
<View style={{ flex: 1, }}>
<SectionList
sections={GraphData.graph}
keyExtractor={(item, index) => item + index}
renderItem={({ item, section }) => {
return null;
}}
renderSectionHeader={({ section }) => (
<>
<Text style={styles.header}>{section.title}</Text>
<FlatList
horizontal
contentContainerStyle={{ flex: 1, alignItems: "stretch" }}
data={section.data}
renderItem={({ item }) => <>
{renderItemView(item)}
</>}
showsHorizontalScrollIndicator={false}
/>
</>
)}
/>
</View>
);
I'm using react-native-web and for the Native side, I'm using import { Picker } from '#react-native-picker/picker'
I'm using a reusable form modal for create and edit. On web, the data populates just fine but on iOS for example, the drop downs don't get set correctly. I've created a reusable component that has react-native-picker/picker as it's child component. So for example I set state on form mount like this:
const [languageAbility, setLanguageAbility] = useState<number>(
childProfile?.languageAbility?.id || 0,
)
const [grade, setGrade] = useState<number>(childProfile?.grade?.id || 0)
and on my components, they are set up like this:
<AccessibleSelect
selectedValue={grade}
options={childMenusData?.menus?.schoolGrades.map((sg) => ({
label: sg.title,
value: sg?.id,
}))}
onValueChange={(val: number) => setGrade(val)}
label={t('ChildForms.Grade')}
testID="grade"
inputStyle={styles.selectStyles}
tooltipText={isMobile ? 'What is a grade?' : ''}
tooltipContent={t('ChildForms.WhatIsAGradeContent')}
tooltipPlacement={'bottom'}
/>
</View>
{!isMobile && (
<View style={styles.inputContainerHalf}>
<Tooltip
text="What is a grade?"
content={t('ChildForms.WhatIsAGradeContent')}
placement={'right'}
/>
</View>
)}
</View>
<View
style={{
flexDirection: isMobile ? 'column' : 'row',
width: '100%',
margin: 0,
}}
>
<View
style={[
styles.inputContainerHalf,
{ marginRight: isMobile ? 0 : 30 },
]}
>
<AccessibleSelect
selectedValue={languageAbility}
options={childMenusData?.menus?.languageAbilities.map((la) => ({
label: la.title,
value: la.id,
}))}
onValueChange={(val: number) => setLanguageAbility(val)}
label={t('ChildForms.LanguageAbility')}
testID="languageAbility"
additionalContainerStyles={{ paddingTop: 0, paddingBottom: 0 }}
inputStyle={styles.selectStyles}
/>
</View>
</View>
And the actual Picker component (AccessibleSelect) looks like this:
return (
<View style={[styles.container, additionalContainerStyles]}>
<Picker
ref={refToAttachToInput}
style={[
Platform.OS === 'ios'
? styles.pickerIOS
: [
styles.picker,
{ borderColor, borderStyle: 'solid', borderWidth: 1 },
],
inputStyle,
]}
selectedValue={selectedValue}
onValueChange={onValueChange}
defaultValue={defaultValue && defaultValue}
itemStyle={styles.pickerText}
mode={isAndroid && 'dropdown'}
>
{options.map((o) => (
<Picker.Item label={o.label} key={o.value} value={o.value} />
))}
</Picker>
<View
style={[
styles.bottomContainer,
{ justifyContent: fieldError ? 'space-between' : 'flex-end' },
]}
>
{!!fieldError && (
<Text accessibilityLiveRegion="assertive" style={styles.errorText}>
{fieldError}
</Text>
)}
</View>
</View>
)
}
I use flipcard(show front - back) to show value but when I change value to show the new one,Flipcard don't back to the front. It still on same page(but value changed)
Example
data1:Front is "A" ,Back is "B"
data2:Front is "X" ,Back is "Y"
I flip A >> B ,Now on flipcard show "B" after that,I update value. Flipcard show "Y" it's not show "X",I have to flip again to "X" . But, I want to show the front of flipcard every new data. How can I do it?
Nextword() {
this.setState({ count: this.state.count + 1 });
}
render() {
return <View>
<View>
<CardFlip ref={(card) => this.card = card} >
<TouchableOpacity onPress={() => this.card.flip()}>
<Text>{this.state.info[this.state.count].item1}</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.card.flip()} >
<Text>{this.state.info[this.state.count].item2}</Text>
</TouchableOpacity>
</CardFlip>
</View >
<View>
<Button title="PRESS1" onPress={this.Nextword.bind(this)}></Button>
</View>
According to the documentation example of react-native-card-flip I just give a style like this to CardFlip component:
style={{
width: 320,
height: 470,
}}
and fix the issue and card flipped.
below the entire code I try:
<View>
<CardFlip
style={{
width: 320,
height: 470,
}}
ref={(card) => (this.card = card)}>
<TouchableOpacity
onPress={() => this.card.flip()}
style={{height: 100, width: 100, backgroundColor: 'green'}}>
<Text>{this.state.info[this.state.count].item1}</Text>
</TouchableOpacity>
<TouchableOpacity
style={{height: 100, width: 100, backgroundColor: 'green'}}
onPress={() => this.card.flip()}>
<Text>{this.state.info[this.state.count].item2}</Text>
</TouchableOpacity>
</CardFlip>
</View>
see the documentation example here: https://github.com/lhandel/react-native-card-flip/blob/master/Example/App.js
I'm mapping over an array to turn a propped state into a number of components.
When I do this, I receive a vertical column of components, not a horizontal one, as you would expect with flexDirection.
This is the styling I have in place:
<View
sytle={{
flexDirection: 'row',
flex: 1,
paddingLeft: 10,
}}
>
{
this.props.team.map(
(v, i) => {
if(v.league.acronym === 'NFL'){
return(
<Check
checked={ this.props.checkedLeagues.includes(v.league.acronym) ? this.state.checked[i] : false }
index={i}
value={v.team_name}
changeCheck={this.changeCheck}
/>
)
}
}
)
}
</View>
I have a piece of components which will be rendered after a user click on a button. However, these components involving too many calculation. It takes 3~5 seconds to complete it.
I want to compute it in advance and store into my state.
So I can show it on the fly.
But somehow, the content always returns null to my state.
Any idea?
prepopulateDetail(){
let displayedSources = {}
this.setState({setState: (
<View>
{
[... new Set(this.props.definition)].map(wordDef => {
if (wordDef.content.length >= 0 && displayedSources.hasOwnProperty(wordDef.source) === false) {
displayedSources[wordDef.source] = true
return (
<View style={styles.definitions} key={guid()} i={wordDef.source}>
<Badge containerStyle={{
backgroundColor: PRIMARY_BG,
width: 100,
marginTop: 5,
marginBottom: 5,
borderRadius: 0
}}>
<Text style={{color: 'white'}}>{wordDef.source.toUpperCase()}</Text>
</Badge>
{
wordDef.content.map((content, j) => {
let data = JSON.parse(content)
return this.displayWordDefinition(data)
})
}
</View>
)
}
})
}
</View>
)}, this.showState)
}