Platform-Specific Code Questions with Answers

14 practice questions on Platform-Specific Code (React Native) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

Where are Android permissions such as CAMERA declared?

  1. AndroidManifest.xml
  2. package.json
  3. Info.plist
  4. build.gradle settings only

Answer: A. AndroidManifest.xml

Explanation

Android permissions are listed in AndroidManifest.xml. Dangerous ones must also be requested at runtime.

Step-by-step solution

  1. Android permissions are declared with uses-permission tags.
  2. These tags are placed in AndroidManifest.xml.
  3. Option A is the correct answer.

Why the other options are wrong

  • B. package.json holds JavaScript dependencies and scripts, not native permissions.
  • C. Info.plist is the iOS configuration file, not the Android one.
  • D. Gradle settings do not declare manifest permissions.

Tip: Declare permissions in the manifest, and request dangerous ones again at runtime.

Question 2Easy

Which runtime API is used to request dangerous permissions on Android from JavaScript?

  1. PermissionsAndroid.request()
  2. Platform.requestPermission()
  3. Linking.askPermission()
  4. AppState.permit()

Answer: A. PermissionsAndroid.request()

Explanation

PermissionsAndroid shows the system dialog and resolves with the result. Declaring the permission in the manifest alone is not enough for dangerous permissions.

Step-by-step solution

  1. Runtime permission requests on Android use the PermissionsAndroid API.
  2. PermissionsAndroid.request() shows the system dialog and resolves with the result.
  3. Option A is the correct answer.

Why the other options are wrong

  • B. Platform has no requestPermission method.
  • C. Linking opens URLs and apps; it does not request permissions.
  • D. AppState tracks foreground and background state; it has no permit method.

Tip: Declare the permission in the manifest, then request dangerous ones at runtime with PermissionsAndroid.request().

Question 3Easy

A project has Button.ios.js and Button.android.js. What does import Button from './Button' load?

  1. Always Button.ios.js, as it comes first
  2. An error, because Button.js does not exist
  3. Both files merged into one component
  4. The file matching the platform being bundled

Answer: D. The file matching the platform being bundled

Explanation

The bundler picks the platform-specific extension automatically, so each platform gets its own implementation.

Step-by-step solution

  1. The bundler resolves platform file extensions such as .ios.js and .android.js.
  2. An import of './Button' is resolved to the file for the platform being built.
  3. Option D describes this, so it is the correct answer.

Why the other options are wrong

  • A. Button.ios.js is only loaded for iOS builds, not always.
  • B. No error occurs, because the platform file is found by the bundler.
  • C. The two files are not merged; only the matching one is loaded.

Tip: Use Name.ios.js and Name.android.js for platform splits; the import path stays the same.

Question 4Easy

Which API shows a short toast message and exists only on Android?

  1. Alert
  2. ToastAndroid
  3. Snackbar
  4. Notification

Answer: B. ToastAndroid

Explanation

ToastAndroid is a core Android-only module. Alert works on both platforms.

Step-by-step solution

  1. ToastAndroid is a core module that shows short toast messages on Android.
  2. It is not available on iOS.
  3. Option B is the correct answer.

Why the other options are wrong

  • A. Alert shows a dialog and works on both platforms.
  • C. Snackbar is not a core React Native API.
  • D. Notification is not the core React Native API for short messages.

Tip: ToastAndroid is Android-only; use Alert or a cross-platform option for both platforms.

Question 5Medium

What is a file named Header.native.js used for?

  1. Mobile-only code, while Header.js serves web
  2. Code that runs only on the Hermes engine
  3. A native module written in JavaScript
  4. Code that is compiled to Swift and Kotlin

Answer: A. Mobile-only code, while Header.js serves web

Explanation

The .native.js extension is picked on both mobile platforms, which is useful when the same project also targets web through react-native-web.

Step-by-step solution

  1. A .native.js file is picked by the bundler for iOS and Android builds.
  2. A plain Header.js file is used for other targets, such as web with react-native-web.
  3. Option A matches this, so it is the correct answer.

Why the other options are wrong

  • B. Hermes is a JavaScript engine; the file suffix does not select an engine.
  • C. The suffix does not make a native module; it only selects mobile code.
  • D. JavaScript files are not compiled into Swift or Kotlin by this suffix.

Tip: Use .native.js for mobile-only variants and a plain .js file for the default.

Question 6Medium

Which API opens the phone dialer from React Native code?

  1. Platform.call('9876543210')
  2. Alert.dial('9876543210')
  3. Linking.openURL('tel:9876543210')
  4. NativeModules.Phone.open()

Answer: C. Linking.openURL('tel:9876543210')

Explanation

Linking opens URLs with any registered handler; the tel: scheme hands the number to the dialer.

Step-by-step solution

  1. Linking.openURL opens URLs.
  2. tel: opens the dialer.

Why the other options are wrong

  • A. No Platform.call.
  • B. Alert has no dial.
  • D. No such module.

Tip: tel: scheme.

Question 7Medium

How are drop shadows usually added on each platform in React Native?

  1. box-shadow strings on both platforms
  2. shadow* props on iOS, elevation on Android
  3. elevation on iOS, shadow* props on Android
  4. Only with images, as neither platform supports it

Answer: B. shadow* props on iOS, elevation on Android

Explanation

iOS uses shadowColor, shadowOffset, shadowOpacity and shadowRadius. Android uses elevation, which also affects stacking order.

Step-by-step solution

  1. IOS shadows are set with shadowColor, shadowOffset, shadowOpacity and shadowRadius.
  2. Android shadows are set with the elevation style.
  3. Option B matches both platforms, so it is the correct answer.

Why the other options are wrong

  • A. Box-shadow is a web CSS property; the usual mobile pair is shadow props and elevation.
  • C. This is reversed: elevation is the Android property and shadow props are the iOS ones.
  • D. Shadows can be set on both platforms with these styles, so this is false.

Tip: IOS uses shadow props and Android uses elevation; set both for a cross-platform shadow.

Question 8Medium

What does Platform.Version return on Android?

  1. The app's versionName string
  2. The React Native version
  3. The Android API level as a number
  4. The device model name

Answer: C. The Android API level as a number

Explanation

On Android, Platform.Version is the API level (an integer). On iOS it is the OS version as a string.

Step-by-step solution

  1. On Android, Platform.Version is the API level.
  2. The API level is an integer that identifies the Android version.
  3. Option C matches, so it is the correct answer.

Why the other options are wrong

  • A. VersionName is an app setting; Platform.Version does not return it.
  • B. Platform.Version does not give the React Native version.
  • D. Platform.Version does not give the device model.

Tip: Platform.Version is a number on Android and a string on iOS, so check the type before comparing.

Question 9Hard

An iOS app accesses the camera without NSCameraUsageDescription in Info.plist. What happens?

  1. The app is terminated when it tries to access it
  2. The camera opens with a generic system message
  3. The permission is granted without asking the user
  4. Only a warning is logged in release builds

Answer: A. The app is terminated when it tries to access it

Explanation

iOS requires a usage description string for protected resources. Without it, the app is killed when it tries to access the resource.

Step-by-step solution

  1. iOS needs a usage description for the camera.
  2. If NSCameraUsageDescription is missing, the system kills the app at access.

Why the other options are wrong

  • B. No dialog appears.
  • C. Permission is never granted silently.
  • D. It crashes, not just a warning.

Tip: No description = crash.

Question 10Hard

On Android, which manifest setting is commonly used so the window resizes when the keyboard opens?

  1. android:keyboardMode="resizeWindow"
  2. android:configChanges="keyboard"
  3. android:windowSoftInputMode="adjustResize"
  4. android:screenOrientation="keyboard"

Answer: C. android:windowSoftInputMode="adjustResize"

Explanation

adjustResize makes the activity's window shrink to fit above the soft keyboard, which many apps pair with KeyboardAvoidingView on iOS.

Step-by-step solution

  1. AdjustResize makes the activity window shrink to sit above the soft keyboard.
  2. This is set with the android:windowSoftInputMode attribute.
  3. Option C has that attribute and value, so it is the correct answer.

Why the other options are wrong

  • A. KeyboardMode is not the attribute that controls keyboard resizing.
  • B. ConfigChanges lists changes the activity handles itself; it does not resize the window.
  • D. ScreenOrientation sets screen rotation, not keyboard resizing.

Tip: For keyboard resizing on Android, use windowSoftInputMode with adjustResize or adjustPan.

Practise all 14 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all React Native topics · All topics