Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 71 additions & 14 deletions example/src/pages/ResponsiveLayouts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
import { Fit, RiveView, useRiveFile } from '@rive-app/react-native';
import { useState, useRef, useEffect } from 'react';
import {
View,
Text,
StyleSheet,
Button,
ActivityIndicator,
useWindowDimensions,
} from 'react-native';
import {
Fit,
RiveView,
useRiveFile,
type RiveViewRef,
} from '@rive-app/react-native';
import { type Metadata } from '../helpers/metadata';

/**
Expand All @@ -11,6 +24,22 @@ export default function ResponsiveLayoutsExample() {
const { riveFile, isLoading, error } = useRiveFile(
require('../../assets/rive/layouts_demo.riv')
);
const [scaleFactor, setScaleFactor] = useState(4.0);
const riveRef = useRef<RiveViewRef>(null);
const { width, height } = useWindowDimensions();

useEffect(() => {
riveRef.current?.playIfNeeded();
}, [width, height]);

const increaseScale = () => {
setScaleFactor((prev) => prev + 0.5);
riveRef.current?.playIfNeeded();
};
const decreaseScale = () => {
setScaleFactor((prev) => Math.max(0.5, prev - 0.5));
riveRef.current?.playIfNeeded();
};

return (
<View style={styles.container}>
Expand All @@ -20,36 +49,64 @@ export default function ResponsiveLayoutsExample() {
<Text style={styles.errorText}>{error}</Text>
) : riveFile ? (
<RiveView
hybridRef={{ f: (ref) => (riveRef.current = ref) }}
file={riveFile}
fit={Fit.Layout}
layoutScaleFactor={1} // adjust the layout scale factor to control the layout scale
layoutScaleFactor={scaleFactor}
style={styles.rive}
autoPlay={true}
/>
) : null}
<View style={styles.controls}>
<Text style={styles.label}>Layout Scale Factor</Text>
<View style={styles.scaleControls}>
<Button title="-" onPress={decreaseScale} />
<View style={styles.scaleText}>
<Text>{scaleFactor.toFixed(1)}x</Text>
</View>
<Button title="+" onPress={increaseScale} />
</View>
</View>
</View>
);
}

ResponsiveLayoutsExample.metadata = {
name: 'Responsive Layouts',
description: 'Interactive layout scale factor controls',
} satisfies Metadata;

const styles = StyleSheet.create({
// Adjust the container size and the layout will adjust based on the .riv file layout rules
container: {
width: '100%',
height: '100%',
flex: 1,
},
rive: {
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
flex: 1,
},
controls: {
padding: 16,
alignItems: 'center',
},
scaleControls: {
flexDirection: 'row',
alignItems: 'center',
marginVertical: 16,
gap: 16,
},
scaleText: {
minWidth: 50,
alignItems: 'center',
},
label: {
fontSize: 16,
fontWeight: '500',
marginTop: 16,
},
errorText: {
color: 'red',
textAlign: 'center',
padding: 20,
flex: 1,
},
});

ResponsiveLayoutsExample.metadata = {
name: 'Responsive Layouts',
description: 'Sample .riv file with responsive layouts',
} satisfies Metadata;
8 changes: 7 additions & 1 deletion expo-example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "expo-example",
"slug": "expo-example",
"version": "1.0.0",
"orientation": "portrait",
"orientation": "default",
"icon": "./assets/images/icon.png",
"scheme": "expoexample",
"userInterfaceStyle": "automatic",
Expand Down Expand Up @@ -40,6 +40,12 @@
"backgroundColor": "#000000"
}
}
],
[
"expo-screen-orientation",
{
"initialOrientation": "DEFAULT"
}
]
],
"experiments": {
Expand Down
1 change: 1 addition & 0 deletions expo-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"expo-image": "~3.0.10",
"expo-linking": "~8.0.8",
"expo-router": "~6.0.13",
"expo-screen-orientation": "~9.0.8",
"expo-splash-screen": "~31.0.10",
"expo-status-bar": "~3.0.8",
"expo-symbols": "~1.0.7",
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8234,6 +8234,7 @@ __metadata:
expo-image: ~3.0.10
expo-linking: ~8.0.8
expo-router: ~6.0.13
expo-screen-orientation: ~9.0.8
expo-splash-screen: ~31.0.10
expo-status-bar: ~3.0.8
expo-symbols: ~1.0.7
Expand Down Expand Up @@ -8412,6 +8413,16 @@ __metadata:
languageName: node
linkType: hard

"expo-screen-orientation@npm:~9.0.8":
version: 9.0.8
resolution: "expo-screen-orientation@npm:9.0.8"
peerDependencies:
expo: "*"
react-native: "*"
checksum: 9971094875bd8756bfa16a88f6a85ef7661e284ffa85a8a415fcb359f3571d2c69ea341edbf6d844dbb007e035bed13c3be0a0c20d569f10048ff5e46683ebc6
languageName: node
linkType: hard

"expo-server@npm:^1.0.3, expo-server@npm:^1.0.4":
version: 1.0.4
resolution: "expo-server@npm:1.0.4"
Expand Down
Loading