Skip to content

Commit 83550ca

Browse files
author
Christoph Pader
authored
Fix: Add axis label padding conditionally (#60)
* fix: only apply padding if top/bottom axis labels are given * turn example controls section into ScrollView
1 parent e327c9d commit 83550ca

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

example/src/screens/GraphPage.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useMemo, useState } from 'react'
2-
import { View, StyleSheet, Text, Button } from 'react-native'
2+
import { View, StyleSheet, Text, Button, ScrollView } from 'react-native'
33
import { LineGraph } from 'react-native-graph'
44
import StaticSafeAreaInsets from 'react-native-static-safe-area-insets'
55
import type { GraphRange } from '../../../src/LineGraphProps'
@@ -104,7 +104,10 @@ export function GraphPage() {
104104

105105
<Button title="Refresh" onPress={refreshData} />
106106

107-
<View style={styles.controls}>
107+
<ScrollView
108+
style={styles.controlsScrollView}
109+
contentContainerStyle={styles.controlsScrollViewContent}
110+
>
108111
<Toggle
109112
title="Animated:"
110113
isEnabled={isAnimated}
@@ -145,7 +148,7 @@ export function GraphPage() {
145148
isEnabled={indicatorPulsating}
146149
setIsEnabled={setIndicatorPulsating}
147150
/>
148-
</View>
151+
</ScrollView>
149152

150153
<View style={styles.spacer} />
151154
</View>
@@ -181,9 +184,11 @@ const styles = StyleSheet.create({
181184
height: 35,
182185
marginLeft: 5,
183186
},
184-
controls: {
187+
controlsScrollView: {
185188
flexGrow: 1,
186-
justifyContent: 'center',
187189
paddingHorizontal: 15,
188190
},
191+
controlsScrollViewContent: {
192+
justifyContent: 'center',
193+
},
189194
})

src/AnimatedLineGraph.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,15 @@ export function AnimatedLineGraph({
457457
pulseTrigger
458458
)
459459

460+
const axisLabelContainerStyle = {
461+
paddingTop: TopAxisLabel != null ? 20 : 0,
462+
paddingBottom: BottomAxisLabel != null ? 20 : 0,
463+
}
464+
460465
return (
461466
<View {...props}>
462467
<GestureDetector gesture={gesture}>
463-
<Reanimated.View style={[styles.container, styles.axisLabelContainer]}>
468+
<Reanimated.View style={[styles.container, axisLabelContainerStyle]}>
464469
{/* Top Label (max price) */}
465470
{TopAxisLabel != null && (
466471
<View style={styles.axisRow}>
@@ -580,9 +585,6 @@ const styles = StyleSheet.create({
580585
container: {
581586
flex: 1,
582587
},
583-
axisLabelContainer: {
584-
paddingVertical: 20,
585-
},
586588
axisRow: {
587589
height: 17,
588590
},

0 commit comments

Comments
 (0)