Accessing device info and triggering haptics usually has minimal impact on frame rate and memory. Device info calls are lightweight and often cached. Haptic feedback uses native hardware, so it does not affect app CPU or memory significantly. However, excessive or continuous haptic triggers can drain battery faster and may cause slight UI jank if called on the main thread too often.
Device info and haptics in React Native - Build, Publish & Deploy
Cache device info results to avoid repeated native calls. Trigger haptics sparingly and only on meaningful user actions to preserve battery and maintain smooth UI. Use asynchronous calls for device info to prevent blocking the UI thread. Avoid triggering haptics in rapid succession to keep 60fps smoothness.
Including device info and haptics libraries adds a small increase to app bundle size, typically under 1MB. This is minor compared to overall app size. Startup time impact is negligible since these features initialize on demand, not at app launch.
On iOS, haptics use the Taptic Engine with predefined feedback types. On Android, haptics use the Vibrator API with more variability across devices. Device info APIs differ: iOS restricts access to some identifiers for privacy, while Android provides more hardware details but requires permissions. React Native libraries abstract these differences but testing on both platforms is essential.
- Ensure you request only necessary permissions for device info (e.g., no unnecessary location or phone state access).
- Respect user privacy: do not collect or transmit device identifiers without consent.
- Follow Apple's Human Interface Guidelines for haptic feedback usage to avoid misuse or annoyance.
- On Google Play, declare vibration permission in the manifest and explain its use if requested.
Your app takes 5 seconds to load this screen that shows device info and triggers haptics. What's likely wrong?
- Device info is fetched synchronously on the main thread, blocking UI rendering.
- Haptics are triggered repeatedly during loading, causing performance drops.
- Unnecessary permissions or heavy native modules increase startup time.
Fix by caching device info, using async calls, and limiting haptic triggers.
Practice
Solution
Step 1: Identify the module for OS info
ThePlatformmodule in React Native gives details about the device OS like 'ios' or 'android'.Step 2: Compare with other modules
Dimensionsgives screen size,Vibrationcontrols haptic feedback, andStatusBarmanages the status bar UI, not OS info.Final Answer:
Platform -> Option AQuick Check:
OS info = Platform [OK]
- Confusing Dimensions with OS info
- Thinking Vibration provides device info
- Assuming StatusBar relates to OS details
Solution
Step 1: Recall Dimensions API usage
The correct method to get screen size isDimensions.get('screen'), which returns an object with width and height.Step 2: Access width property correctly
Access the width by.widthproperty, soDimensions.get('screen').widthis correct syntax.Final Answer:
Dimensions.get('screen').width -> Option CQuick Check:
Screen width = Dimensions.get('screen').width [OK]
- Calling width as a function instead of property
- Using wrong method names like getWidth
- Accessing screen as a property instead of argument
import { Vibration } from 'react-native';
Vibration.vibrate(1000);
Choose the correct behavior.Solution
Step 1: Understand Vibration.vibrate parameter
Passing a number like 1000 toVibration.vibrate()makes the device vibrate for that many milliseconds (1000 ms = 1 second).Step 2: Check other options
Indefinite vibration requires a pattern with repeat, 100 ms is too short, and vibrate accepts a number directly, so no pattern array is needed.Final Answer:
The device vibrates for 1 second -> Option AQuick Check:
Vibration.vibrate(1000) = 1 second vibration [OK]
- Thinking vibrate needs a pattern array always
- Confusing milliseconds with seconds
- Assuming vibrate runs indefinitely by default
import { Vibration } from 'react-native';
Vibration.vibrate([500, 1000]);Solution
Step 1: Check Vibration.vibrate pattern usage
Vibration.vibrate accepts an array pattern as first argument to define vibration and pause durations.Step 2: Understand repeat flag necessity
To repeat the pattern, a second boolean argumenttrueis needed. Without it, the pattern runs once, so no error but possibly unintended behavior.Final Answer:
The array pattern is correct but missing a repeat flag -> Option BQuick Check:
Pattern array needs repeat flag to loop [OK]
- Thinking array is invalid argument
- Forgetting second argument for repeat
- Passing array as second argument instead of first
Solution
Step 1: Understand the required pattern
The pattern is vibrate 500ms, pause 300ms, repeated twice:[500, 300, 500, 300].Step 2: Use repeat false to play exactly twice
Vibration.vibrate([500, 300, 500, 300], false)executes the sequence once without looping further.Step 3: Eliminate other options
Usingtruecauses indefinite looping (cancel timing imprecise); shorter pattern loops incorrectly; separate calls lack pauses.Final Answer:
Vibration.vibrate([500, 300, 500, 300], false); -> Option DQuick Check:
Two pattern repeats = [500, 300, 500, 300], false [OK]
- Using repeat true without precise cancel
- Using false for repeat flag
- Calling vibrate multiple times instead of pattern
Ready to prove it?
Pass the test and this pattern moves unknown
