Merge pull request 'fix(mobile): keep native menu trigger stable across focus changes' (#44) from t3/fix-mobile-content-disappearing into main
This commit was merged in pull request #44.
This commit is contained in:
commit
34a08454c4
2 files changed
+69
-1
No files matched your search
@@ -0,0 +1,65 @@
|
||||
const { test } = require("node:test")
|
||||
const assert = require("node:assert/strict")
|
||||
const fs = require("node:fs")
|
||||
const vm = require("node:vm")
|
||||
const ts = require("typescript")
|
||||
|
||||
test("the native menu keeps its trigger type when screen focus replaces the Siri wrapper", () => {
|
||||
let focused = true
|
||||
const imports = {
|
||||
"react/jsx-runtime": {
|
||||
jsx: (type, props) => ({ type, props }),
|
||||
jsxs: (type, props) => ({ type, props }),
|
||||
},
|
||||
"react-native": { Platform: { OS: "ios" }, View: "View" },
|
||||
expo: { requireNativeView: (_module, view) => view },
|
||||
"expo-router": { useIsFocused: () => focused },
|
||||
"expo-app-intents": { AppEntityView: "AppEntityView" },
|
||||
"@expo/ui/community/menu": {},
|
||||
"@/contexts/server-config": { useServerConfig: () => ({ config: null }) },
|
||||
"@/lib/media-links": { shouldShowShare: () => false },
|
||||
"@/lib/share-media-link": {},
|
||||
}
|
||||
|
||||
function load(file) {
|
||||
const module = { exports: {} }
|
||||
const source = ts.transpileModule(
|
||||
fs.readFileSync(`${__dirname}/${file}.tsx`, "utf8"),
|
||||
{
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
}
|
||||
).outputText
|
||||
vm.runInNewContext(source, {
|
||||
module,
|
||||
exports: module.exports,
|
||||
require: (name) => {
|
||||
assert.ok(name in imports, `Unexpected import ${name}`)
|
||||
return imports[name]
|
||||
},
|
||||
})
|
||||
return module.exports
|
||||
}
|
||||
|
||||
const { MusicEntityView } = load("music-entity-view")
|
||||
const { MediaContextMenu } = load("media-context-menu")
|
||||
const card = { type: "Pressable", props: { children: "Album" } }
|
||||
const triggers = []
|
||||
|
||||
for (const nextFocus of [true, false, true, false, true]) {
|
||||
focused = nextFocus
|
||||
const entity = MusicEntityView({ kind: "album", id: "1", children: card })
|
||||
const menu = MediaContextMenu({ children: entity, onAction() {} })
|
||||
const nativeMenu = menu.type(menu.props)
|
||||
const trigger = nativeMenu.props.children[0]
|
||||
triggers.push(trigger)
|
||||
|
||||
// Fabric must retain this host even when its child changes native type.
|
||||
assert.equal(trigger.props.collapsable, false)
|
||||
assert.equal(trigger.type, triggers[0].type)
|
||||
assert.equal(trigger.props.children.type, focused ? "AppEntityView" : "View")
|
||||
assert.equal(trigger.props.children.props.children, card)
|
||||
}
|
||||
})
|
||||
@@ -3,6 +3,7 @@ import { requireNativeView } from "expo"
|
||||
import type { ComponentType, ReactNode } from "react"
|
||||
import {
|
||||
Platform,
|
||||
View,
|
||||
type StyleProp,
|
||||
type ViewProps,
|
||||
type ViewStyle,
|
||||
@@ -241,7 +242,9 @@ function NativeMediaContextMenu({
|
||||
|
||||
return (
|
||||
<NativeContextMenuView style={{ display: "contents" }} disableForceFlatten>
|
||||
{children}
|
||||
{/* The native menu retains its first trigger. Keep that view mounted when
|
||||
focus changes replace the Siri entity wrapper inside it. */}
|
||||
<View collapsable={false}>{children}</View>
|
||||
{buildMediaMenuActions({ ...actionConfig, share }).map((action) => (
|
||||
<NativeContextMenuAction
|
||||
key={action.id}
|
||||
|
||||
Reference in new issue
Block a user