React Native Plugin
React Native Plugin
Section titled “React Native Plugin”The @strata-game-library/react-native provides native mobile capabilities for React Native games built with Strata.
Installation
Section titled “Installation”npm install @strata-game-library/react-nativeiOS Setup
Section titled “iOS Setup”cd ios && pod installAndroid Setup
Section titled “Android Setup”Automatically linked via autolinking.
Features
Section titled “Features”- Device Detection - Identify device type, platform, and performance capabilities
- Input Handling - Unified touch input with
StrataInputProvider - Gamepad Support - iOS GameController/MFi and Android InputDevice controller detection plus native input snapshots
- Haptic Feedback - iOS Taptic Engine, Android Vibrator
- Safe Area Insets - Native detection for notches
- Orientation - Get and lock screen orientation
- Performance Mode - Detect low power mode
useDevice()
Section titled “useDevice()”Returns the current device profile:
import { useDevice } from '@strata-game-library/react-native';
function Game() { const device = useDevice();
// Adapt UI based on device if (device.deviceType === 'tablet') { return <TabletLayout />; }
// Check safe areas for notch const style = { paddingTop: device.safeAreaInsets.top, paddingBottom: device.safeAreaInsets.bottom, };
return <View style={style}>{/* Game content */}</View>;}useInput()
Section titled “useInput()”Returns the current input state. Touches come from StrataInputProvider; native controller snapshots are polled when the installed native module exposes getInputSnapshot():
import { useInput, StrataInputProvider } from '@strata-game-library/react-native';
function Game() { const input = useInput();
// Use joystick values for movement const moveX = input.leftStick.x; const moveY = input.leftStick.y;
// Check button presses if (input.buttons.a) { player.jump(); }
return <GameCanvas movement={[moveX, moveY]} />;}
// Wrap with providerfunction App() { return ( <StrataInputProvider> <Game /> </StrataInputProvider> );}useHaptics()
Section titled “useHaptics()”Returns haptic feedback controls:
import { useHaptics } from '@strata-game-library/react-native';
function Game() { const { trigger } = useHaptics();
const handleCollision = async () => { await trigger({ intensity: 'medium' }); };
const handleExplosion = async () => { await trigger({ intensity: 'heavy', duration: 200, }); };
const handlePattern = async () => { await trigger({ duration: 100, }); };
return <GameCanvas onCollision={handleCollision} />;}useControlHints()
Section titled “useControlHints()”Returns localized control hints based on input mode:
import { useControlHints } from '@strata-game-library/react-native';
function ControlsOverlay() { const hints = useControlHints();
return ( <View> <Text>{hints.movement}</Text> {/* "Drag to move" or "WASD to move" */} <Text>{hints.action}</Text> {/* "Tap to jump" or "Space to jump" */} <Text>{hints.camera}</Text> {/* "Swipe to look" or "Mouse to look" */} </View> );}Components
Section titled “Components”<StrataInputProvider>
Section titled “<StrataInputProvider>”Wraps your app to capture and process input events:
import { StrataInputProvider } from '@strata-game-library/react-native';
function App() { return ( <StrataInputProvider onInput={(snapshot) => { // Process raw input console.log(snapshot.touches); }} > <Game /> </StrataInputProvider> );}Utilities
Section titled “Utilities”setOrientation()
Section titled “setOrientation()”Lock screen orientation:
import { setOrientation } from '@strata-game-library/react-native';
// Lock to landscapeawait setOrientation('landscape');
// Lock to portraitawait setOrientation('portrait');
// Unlockawait setOrientation('default');Performance Tier
Section titled “Performance Tier”Use useDevice().performanceMode to adapt graphics:
const { performanceMode } = useDevice();const graphicsSettings = { low: { shadows: false, particles: 100 }, medium: { shadows: true, particles: 500 }, high: { shadows: true, particles: 2000 },}[performanceMode];Platform Support
Section titled “Platform Support”| Feature | iOS | Android |
|---|---|---|
| Device Detection | ✅ | ✅ |
| Touch Input | ✅ | ✅ |
| Haptics (Light) | ✅ Taptic | ✅ |
| Haptics (Heavy) | ✅ Taptic | ✅ |
| Safe Area Insets | ✅ | ✅ |
| Orientation Lock | ✅ | ✅ |
| Gamepad Detection | ✅ GameController/MFi | ✅ InputDevice |
| Native Input Snapshot | ✅ | ✅ |
| Performance Detection | ✅ | ✅ |
| Low Power Mode | ✅ | ✅ |
Performance Tips
Section titled “Performance Tips”- Use
useMemofor input processing to avoid re-renders - Debounce haptics to prevent rapid successive calls
- Use controller-aware hints from
useControlHints()whenuseDevice()reportsinputMode: 'gamepad' - Use orientation lock to prevent layout shifts during gameplay
Related
Section titled “Related”- Capacitor Plugin - Alternative for web-first apps
- Mobile Plugins Overview - Feature comparison