-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
279 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
/* eslint-disable import/no-duplicates */ | ||
/* eslint-disable prettier/prettier */ | ||
import "react-native-gesture-handler"; | ||
import { Slot } from "expo-router"; | ||
import { StyleSheet } from "react-native"; | ||
import { GestureHandlerRootView } from "react-native-gesture-handler"; | ||
|
||
export default Slot; | ||
export default () => ( | ||
<GestureHandlerRootView style={styles.container}> | ||
<Slot /> | ||
</GestureHandlerRootView> | ||
); | ||
|
||
const styles = StyleSheet.create({ container: { flex: 1 } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
import { LineChart } from "@codeherence/react-native-graph"; | ||
import { useMemo } from "react"; | ||
import { StyleSheet, View } from "react-native"; | ||
import { useCallback, useState } from "react"; | ||
import { Button, StyleSheet, View } from "react-native"; | ||
import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
||
import { Banner } from "../components/Banner"; | ||
|
||
const generateRandomData = (): [number, number][] => { | ||
return Array.from({ length: 100 }, (_, i) => [i, Math.random() * 2000]); | ||
}; | ||
|
||
export default () => { | ||
const { top, bottom } = useSafeAreaInsets(); | ||
const [data, setData] = useState<[number, number][]>(generateRandomData()); | ||
|
||
const data: [number, number][] = useMemo(() => { | ||
return Array.from({ length: 20 }, (_, i) => [i, Math.random() * 2000]); | ||
const handlePress = useCallback(() => { | ||
setData(generateRandomData()); | ||
}, []); | ||
|
||
return ( | ||
<View style={[styles.container, { paddingTop: top, paddingBottom: bottom }]}> | ||
<LineChart | ||
points={data} | ||
style={styles.chart} | ||
BannerComponent={Banner} | ||
TopAxisLabel={() => <View />} | ||
/> | ||
<Button title="Randomize data" onPress={handlePress} /> | ||
<LineChart points={data} style={styles.chart} BannerComponent={Banner} /> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { flex: 1 }, | ||
chart: { flex: 1, maxHeight: 200 }, | ||
chart: { flex: 1 }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,66 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { useCallback, useState } from "react"; | ||
import { LayoutChangeEvent } from "react-native"; | ||
import Reanimated from "react-native-reanimated"; | ||
import { LayoutChangeEvent, StyleSheet, View } from "react-native"; | ||
import Reanimated, { | ||
clamp, | ||
useAnimatedStyle, | ||
useDerivedValue, | ||
withTiming, | ||
} from "react-native-reanimated"; | ||
|
||
export interface AxisLabelComponentProps { | ||
value: number; | ||
} | ||
|
||
interface AxisLabelContainerProps { | ||
children: React.ReactNode; | ||
x: number; | ||
containerWidth: number; | ||
} | ||
|
||
export const AxisLabelContainer: React.FC<AxisLabelContainerProps> = ({ children }) => { | ||
const [_, setWidth] = useState(0); | ||
const [__, setHeight] = useState(0); | ||
export const AxisLabelContainer: React.FC<AxisLabelContainerProps> = ({ | ||
x, | ||
containerWidth, | ||
children, | ||
}) => { | ||
const [width, setWidth] = useState(0); | ||
|
||
const onLayout = useCallback((event: LayoutChangeEvent) => { | ||
setWidth(event.nativeEvent.layout.width); | ||
setHeight(event.nativeEvent.layout.height); | ||
}, []); | ||
|
||
return <Reanimated.View onLayout={onLayout}>{children}</Reanimated.View>; | ||
const translateX = useDerivedValue(() => { | ||
const halfWidth = Math.round(width / 2); | ||
const minX = 0; | ||
const maxX = containerWidth - width; | ||
|
||
return withTiming(clamp(x - halfWidth, minX, maxX)); | ||
}, [x, containerWidth, width]); | ||
|
||
const transform = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: translateX.value }], | ||
}; | ||
}); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Reanimated.View style={[styles.child, transform]} onLayout={onLayout}> | ||
{children} | ||
</Reanimated.View> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
position: "relative", | ||
flexDirection: "row", | ||
width: "100%", | ||
overflow: "hidden", | ||
}, | ||
child: { | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
}); |
Oops, something went wrong.