Skip to content

Commit b5a3e97

Browse files
committed
feat: add interactive scale factor controls to ResponsiveLayouts
1 parent 7800820 commit b5a3e97

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

example/src/pages/ResponsiveLayouts.tsx

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,74 @@
1-
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
1+
import { useState } from 'react';
2+
import { View, Text, StyleSheet, Button } from 'react-native';
3+
import { SafeAreaView } from 'react-native-safe-area-context';
24
import { Fit, RiveView, useRiveFile } from '@rive-app/react-native';
35
import { type Metadata } from '../helpers/metadata';
46

5-
/**
6-
* Demonstrates responsive layouts using Fit.Layout and layoutScaleFactor
7-
*
8-
* See https://rive.app/docs/runtimes/layout
9-
*/
107
export default function ResponsiveLayoutsExample() {
11-
const { riveFile, isLoading, error } = useRiveFile(
8+
const { riveFile } = useRiveFile(
129
require('../../assets/rive/layouts_demo.riv')
1310
);
11+
const [scaleFactor, setScaleFactor] = useState(4.0);
12+
13+
const increaseScale = () => setScaleFactor((prev) => prev + 0.5);
14+
const decreaseScale = () =>
15+
setScaleFactor((prev) => Math.max(0.5, prev - 0.5));
1416

1517
return (
16-
<View style={styles.container}>
17-
{isLoading ? (
18-
<ActivityIndicator size="large" color="#0000ff" />
19-
) : error ? (
20-
<Text style={styles.errorText}>{error}</Text>
21-
) : riveFile ? (
18+
<SafeAreaView style={styles.container}>
19+
{riveFile && (
2220
<RiveView
2321
file={riveFile}
2422
fit={Fit.Layout}
25-
layoutScaleFactor={1} // adjust the layout scale factor to control the layout scale
23+
layoutScaleFactor={scaleFactor}
2624
style={styles.rive}
25+
autoPlay={true}
2726
/>
28-
) : null}
29-
</View>
27+
)}
28+
<View style={styles.controls}>
29+
<Text style={styles.label}>Layout Scale Factor</Text>
30+
<View style={styles.scaleControls}>
31+
<Button title="-" onPress={decreaseScale} />
32+
<View style={styles.scaleText}>
33+
<Text>{scaleFactor.toFixed(1)}x</Text>
34+
</View>
35+
<Button title="+" onPress={increaseScale} />
36+
</View>
37+
</View>
38+
</SafeAreaView>
3039
);
3140
}
3241

42+
ResponsiveLayoutsExample.metadata = {
43+
name: 'Responsive Layouts',
44+
description: 'Interactive layout scale factor controls',
45+
} satisfies Metadata;
46+
3347
const styles = StyleSheet.create({
34-
// Adjust the container size and the layout will adjust based on the .riv file layout rules
3548
container: {
36-
width: '100%',
37-
height: '100%',
49+
flex: 1,
3850
},
3951
rive: {
40-
justifyContent: 'center',
41-
alignItems: 'center',
4252
width: '100%',
43-
height: '100%',
53+
flex: 1,
4454
},
45-
errorText: {
46-
color: 'red',
47-
textAlign: 'center',
48-
padding: 20,
55+
controls: {
56+
padding: 16,
57+
alignItems: 'center',
58+
},
59+
scaleControls: {
60+
flexDirection: 'row',
61+
alignItems: 'center',
62+
marginVertical: 16,
63+
gap: 16,
64+
},
65+
scaleText: {
66+
minWidth: 50,
67+
alignItems: 'center',
68+
},
69+
label: {
70+
fontSize: 16,
71+
fontWeight: '500',
72+
marginTop: 16,
4973
},
5074
});
51-
52-
ResponsiveLayoutsExample.metadata = {
53-
name: 'Responsive Layouts',
54-
description: 'Sample .riv file with responsive layouts',
55-
} satisfies Metadata;

0 commit comments

Comments
 (0)