Explore the learn-p5 Expo app codebase (thorough). I need to understand the custom "qwerty keyboard" component used in the exercises view.
Find:
The QWERTY keyboard component file path. It's a custom on-screen keyboard for entering code on mobile.
Specifically find the "popup that shows on keypress" - the visual indicator/popup that appears when a key is pressed. Report exactly how it's positioned. The current bug: the popup shows at the same place as the pressed key instead of over it. Find the code that computes the popup position.
Report the relevant styling/layout code, the key layout structure, and how the pressed key's position is tracked.
Report back: file paths, line numbers, and code snippets of the popup positioning logic. Be thorough.
Assistant
I'll explore the codebase to find the QWERTY keyboard component and the popup positioning logic.
Assistant
Found relevant files. Let me read all of them to understand the keyboard structure and popup logic.
Assistant
I have a complete picture. Here is a thorough report of the QWERTY keyboard component, its popup, the positioning logic, and the root cause of the bug.
1. Component file paths
/workspaces/learn-p5/src/components/QwertyKeyboard.tsx — the custom on-screen QWERTY keyboard (the one with the long-press popup). 667 lines total.
/workspaces/learn-p5/src/components/ProgrammingKeyboard.tsx — the other keyboard (a p5 symbol/function palette). Its "popup" is a full-screen Modal reference card (lines 252-291), unrelated to the keypress-position popup you're describing. So the bug is not here.
/workspaces/learn-p5/src/data/keyboardLayout.ts — shared symbol/function definitions (no positioning logic).
The bug lives entirely in QwertyKeyboard.tsx.
2. Key layout structure
Three letter rows are defined as static arrays (lines 41-80):
And the popup style (lines 649-661) — absolutely positioned inside the keyboard container (the container is the position-establishing parent since the popup's top/left are relative to it):
5. Root cause of the bug — the popup is rendered at a constant location, not over the pressed key
The popup is always rendered at essentially the same left and top, regardless of which key was long-pressed.
Why:handleKeyLayout (lines 134-137) reads event.nativeEvent.layout.x / .y from the Pressable. In React Native, those coordinates are relative to the Pressable's immediate parent. Look at the render structure (lines 286-289):
tsx
287: <View key={key.primary}> // wrapping View, no styles, only child of the row
288: <Pressable
289: onLayout={(e) => handleKeyLayout(key.primary, e)} // measures Pressable inside the View
Every letter key is wrapped in its own empty <View>, and the Pressable is the only child of that wrapping View (which has no padding/margin). So for every key, the Pressable's onLayout reports x: 0, y: 0 (plus its own w/h). The Pressable's actual position within the row (driven by flexbox order + the row's paddingLeft inset + gap) is never captured, because that position belongs to the wrapping <View>, not the Pressable.
Consequences in showPopup:
Line 151: centerX = layout.x + layout.w / 2 → 0 + keySize/2 for every key. A constant.
Line 152: left = centerX - w / 2 → a constant for every key (clamped only at screen edges by lines 153-154).
Line 156: setPopupLayout({ x: centerX, y: layout.y }) → y: 0 for every key (the Pressable's y inside its wrapping View is 0; the row's y within the container is never added).
Then in renderPopup:
Line 230: top = popupLayout.y - ALT_CELL_HEIGHT - POPUP_TOP_OFFSET = 0 - 58 - 6 = -64 → always negative.
Line 238: because top > 0 is false, it always falls to the else branch: popupLayout.y + dims.keyHeight + POPUP_TOP_OFFSET = 0 + keyHeight + 6. A constant.
So popupRowLeft is a constant left offset and top is a constant keyHeight + 6 — the popup always appears in the same spot (just below where ROW1 sits, at a fixed horizontal center), no matter which key you long-press. That matches the reported bug exactly: "the popup shows at the same place… instead of over it."
The same problem affects finger-slide selection
handleTouchMove (lines 189-198) maps e.nativeEvent.pageX onto the popup row using containerScreenXRef.current + popupRowLeft. Because popupRowLeft is derived from the same broken centerX (constant), the slide-to-pick gesture also operates against a mispositioned reference. Fixing the position will fix the selection mapping too.
6. What a fix needs to touch
The positioning math (showPopup, lines 139-169) and renderPopup (lines 228-246) is internally consistent; the bug is upstream — keyLayouts.current[key] stores coordinates relative to the wrong ancestor. Two viable approaches:
Move onLayout to the wrapping <View> (line 287) instead of the Pressable. That View is a direct child of the row, so its x reflects the key's actual horizontal position within the row. But y would still be 0 relative to its row — you'd also need to add each row's vertical offset within keysContainer (the rows are siblings separated by gap: KEY_GAP, with the keysContainer itself offset below the toolbar).
Use measure/measureLayout relative to containerRef (the keyboard root View, line 428) for each key — this gives true container-relative x/y directly, which is exactly what showPopup and renderPopup assume (left: popupRowLeft, top calculated from popupLayout.y both treat the values as container-relative, since styles.popup is position: "absolute" inside the container at line 428/434/650).
Approach 2 is the most robust and matches the existing intent of the math (lines 147-149 already use containerRef.current?.measure(...) to grab the container's screen-x; the keys just need to be measured relative to that same container).
Summary of relevant line ranges in /workspaces/learn-p5/src/components/QwertyKeyboard.tsx
Concern
Lines
Layout constants (popup sizing/offset)
84-93
keyLayouts ref + container refs
118-120
dims (key size math)
122-132
handleKeyLayout — stores wrong-coordinate layout
134-137
showPopup — uses layout.x/.y to compute center/left/top
139-169
handlePressIn (long-press triggers showPopup)
171-183
handleTouchMove — finger-slide, also uses popupRowLeft
189-198
handlePressOut — dismiss/insert
200-226
renderPopup — applies left: popupRowLeft, top
228-279
renderLetterKey — the View→Pressable wrapper (the onLayout target)