The Number Guessing Game — iOS Polish
Lesson opener
In one line: Reuse identical game logic from android5.
Why it matters: This shows up at work when you need to reuse identical game logic from android5.
Before this lesson: android5
Before you start
| Resource | Link |
|---|---|
| Previous | RN fundamentals (iOS) |
| Next | Polish & accessibility |
| Prerequisites | Complete android5 game on Mac |
| Time | ~60 minutes |
What you will learn
- Reuse identical game logic from android5
- iOS navigation bar styling
- Haptic feedback on guess and win
Alert.alertiOS presentation
Copy all files from android5: App.js, utils/storage.js, screens/*.
Section 1 — iOS navigation options
In App.js, use stack options that feel native on iOS:
<Stack.Navigator
screenOptions={{
headerBackTitleVisible: true, // iOS shows previous screen name
headerLargeTitle: false,
}}
>Wrap root in SafeAreaProvider + screens in SafeAreaView (ios2).
Section 2 — Haptic feedback (iOS polish)
npx expo install expo-hapticsIn GameScreen.js:
import * as Haptics from 'expo-haptics';
// Inside checkGuess, after valid n computed:
if (n < target || n > target) {
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
// ... set hint too high/low
} else {
await Haptics.notificationAsync(
Haptics.NotificationFeedbackType.Success
);
navigation.replace('Result', { attempts: nextAttempts });
}Plain English: iOS users feel subtle taps — Android uses Vibration API instead. Haptics are optional polish, not required for logic.
Section 3 — iOS-style colours
Use system-like neutrals (iOS Settings app feel):
const iosColors = {
background: '#F2F2F7',
label: '#000000',
secondaryLabel: '#3C3C43',
tint: '#007AFF',
};Apply to HomeScreen container background and link-colour buttons.
Section 4 — Expected UI (iOS game screen)
Checklist
- [ ] Same game logic as android5 runs on iOS Simulator
- [ ] Haptics fire on wrong/correct guess (device only — simulator limited)
- [ ] SafeAreaView prevents notch overlap
Teacher walkthrough: port the game loop carefully
All figures illustrative.
Step 1 — Bring the Android game rules unchanged. Timing and score must match the Android track.
Step 2 — Input and performance. Touch handling and frame timing on simulator; avoid JS thrash in the loop.
Step 3 — Persist high score before background (lifecycle from ios1).
Step 4 — Store readiness. Minimum functionality and crash-free review path.
Failure example: high score lost on app switch
Symptom: Players lose progress when taking a call.
Diagnosis: Saved only on "Game Over", not on blur/background.
Correction: Persist on background; restore on resume; test interruption.
Validation: Background mid-game → resume → score/state intact.
Guided practice
List three events that should trigger a save in a simple RN game on iOS.
Complete solution: Background/blur; game over; meaningful level/checkpoint change (not every frame).
Independent practice
Acceptance criteria:
- Game runs on iOS simulator without crash in a 2-minute play.
- High score persists across kill/reopen.
- Rules match Android version (or differences documented).
- One performance note (what you measured or watched).
Common mistakes
- Saving every animation frame (jank + wear).
- Hardcoding Android asset paths.
- Shipping with debug overlays visible.
What's next
Polish & accessibility — dark mode and Dynamic Type.