Fixing the 10-Second Walk Button Delay
Tapping 'Start Walk' froze for 10 seconds with no feedback. Sequential async calls, a blocking alert, and a slow GPS lock were all compounding.
When users tapped "Start Walk," nothing happened for 10 seconds. No spinner, no feedback -- just a frozen button. Then the tracking screen appeared. The flow was:
User taps "Start Walk"
1. requestPermissions() ~1-2s
2. Alert.alert() for background BLOCKING (waits for tap)
3. getCurrentLocation(high accuracy) 5-10 SECONDS
4. createWalkSession() ~100ms
5. startBackgroundTracking() ~500ms
UI finally transitions
The main culprit: getCurrentLocation() with high accuracy waits for a precise GPS lock, which takes 5-10 seconds if GPS hasn't been used recently.
Fix 1: Fast Location First
// BEFORE: wait for precise GPS (5-10 seconds)
const initialLocation = await getCurrentLocation();
// AFTER: low-accuracy for instant response (~500ms)
const initialLocation = await getCurrentLocation(true); // fast mode
Low accuracy is fine for centering the map. Background location tracking (started immediately after) delivers high-accuracy updates within seconds.
Fix 2: Non-Blocking Alert
// BEFORE: alert blocks the entire flow
if (!permissions.backgroundLocation) {
Alert.alert('Background Location Required', ...); // BLOCKING
}
// AFTER: show alert after UI transition
const shouldShowAlert = !permissions.backgroundLocation;
// ... start session, transition UI ...
if (shouldShowAlert) {
setTimeout(() => Alert.alert('Background Location Required', ...), 500);
}
Fix 3: Loading Feedback
const [isStartingWalk, setIsStartingWalk] = useState(false);
<TouchableOpacity
style={[styles.startButton, isStartingWalk && styles.startButtonDisabled]}
onPress={handleStartWalk}
disabled={isStartingWalk}
>
{isStartingWalk ? (
<ActivityIndicator color="#fff" size="small" />
) : (
<><Ionicons name="walk" size={24} color="#fff" /><Text>Start Walk</Text></>
)}
</TouchableOpacity>
Result
| Metric | Before | After |
|---|---|---|
| Time to tracking screen | ~10 seconds | <1 second |
| User feedback | None | Loading spinner |
| Alert behavior | Blocking | Non-blocking |
| Initial GPS | High accuracy (slow) | Low (fast) → High (background) |
Same fix applied to "End Walk" -- no need to wait for a precise GPS lock when the walk was already tracked with high-accuracy background updates the entire time.
Built while working on PlanPal.
Back to danielships ->