Skip to content

Commit aad6bc0

Browse files
committed
Add native menus and glass containers
1 parent accc4ce commit aad6bc0

25 files changed

Lines changed: 395 additions & 67 deletions

‎apps/adventure-arena/Controller.lua‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ end
4141

4242
function Controller:push(template, data, title)
4343
local view, refs = xml.renderFile("apps/adventure-arena/views/" .. template .. ".etlua", data, self.ns)
44-
local hostingController
45-
if template == "Session" and self.ns.SpeechRecognizer then
46-
hostingController = self.ns.HostingController(view, function()
44+
local onDisappear
45+
if template == "Session" then
46+
onDisappear = function()
4747
self.sessionController:onDisappear()
48-
end)
49-
else
50-
hostingController = self.ns.HostingController(view)
48+
end
5149
end
50+
local hostingController = self.ns.HostingController(view, onDisappear, {
51+
hidesTabBar = template == "Session",
52+
})
5253
self.navigation:push(hostingController, title)
5354
return view, refs
5455
end

‎apps/adventure-arena/controllers/SessionController.lua‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ function Controller:show(id)
3333
end
3434
local actions = {
3535
submit = function() self:submitCommand(self.refs.input.text) end,
36+
inputChanged = function(text) self:updateComposer(text) end,
37+
inputCommand = function(command)
38+
if command ~= "submit" then return false end
39+
self:submitCommand(self.refs.input.text)
40+
return true
41+
end,
3642
look = function() self:submitCommand("look") end,
3743
inventory = function() self:submitCommand("inventory") end,
3844
dictate = function() self:toggleDictation() end,
@@ -44,14 +50,20 @@ function Controller:show(id)
4450
actions = actions,
4551
}, game.title)
4652
self.refs.input.accessibilityLabel = "Command"
47-
self.ns._textFieldCallbacks(self.refs.input, nil, function(command)
48-
if command ~= "submit" then return false end
49-
actions.submit()
50-
return true
51-
end)
53+
self:updateComposer(self.refs.input.text)
5254
return true
5355
end
5456

57+
function Controller:updateComposer(text)
58+
if not self.refs then return end
59+
local hasText = type(text) == "string" and text:find("%S") ~= nil
60+
local showSend = not self.refs.dictate or (hasText and not self.dictationActive)
61+
self.refs.send.hidden = not showSend
62+
self.refs.send.enabled = hasText
63+
if self.refs.dictate then self.refs.dictate.hidden = showSend end
64+
self.view:layout()
65+
end
66+
5567
function Controller:onSpeechEvent(state, text, message)
5668
if not self.refs then return end
5769
if state == "listening" then
@@ -76,7 +88,7 @@ function Controller:onSpeechEvent(state, text, message)
7688
self.dictationActive = false
7789
self.refs.dictationStatus.text = ""
7890
end
79-
self.view:layout()
91+
self:updateComposer(self.refs.input.text)
8092
end
8193

8294
function Controller:toggleDictation()
@@ -89,7 +101,7 @@ function Controller:toggleDictation()
89101
self.dictationActive = true
90102
self.speech:start()
91103
end
92-
self.view:layout()
104+
self:updateComposer(self.refs.input.text)
93105
end
94106

95107
function Controller:cancelDictation()
@@ -110,12 +122,13 @@ function Controller:onDisappear()
110122
end
111123

112124
function Controller:submitCommand(command)
125+
if type(command) ~= "string" or not command:find("%S") then return false end
113126
self:cancelDictation()
114127
local ok, err = self.model:submit(command)
115128
self.refs.output.text = self.model:transcript()
116129
self.refs.input.text = ""
117130
self.refs.dictationStatus.text = ""
118-
self.view:layout()
131+
self:updateComposer("")
119132
return ok, err
120133
end
121134

‎apps/adventure-arena/views/Session.etlua‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
</VStack>
66
</ScrollView>
77
<Label ref="dictationStatus" text="" size="13" color="secondary" paddingHorizontal="20" lines="2" />
8-
<HStack paddingHorizontal="16" spacing="10">
9-
<GlassEffect style="regular" cornerRadius="28" maxWidth="infinity">
10-
<HStack paddingHorizontal="14" spacing="8" minHeight="56">
11-
<TextField ref="input" placeholder="What do you want to do?" maxWidth="infinity" />
12-
<% if speechAvailable then %>
13-
<Button ref="dictate" title="" systemImage="mic" accessibilityLabel="Dictate command" action="dictate" style="plain" />
14-
<% end %>
15-
</HStack>
16-
</GlassEffect>
17-
<Button ref="send" title="Send" action="submit" style="plain" />
18-
</HStack>
19-
<HStack paddingHorizontal="16" paddingBottom="8">
20-
<Button ref="look" title="look" action="look" />
21-
<Button ref="inventory" title="inventory" action="inventory" />
22-
<Spacer />
23-
<Button ref="close" title="End session" action="close" />
24-
</HStack>
8+
<GlassEffectContainer spacing="14">
9+
<HStack paddingHorizontal="12" paddingBottom="8" spacing="8" alignment="bottom">
10+
<Menu ref="quickActions" title="" systemImage="plus" symbolSize="31" style="glass" accessibilityLabel="More commands" width="52" height="52">
11+
<MenuItem title="Look" systemImage="eye" action="look" />
12+
<MenuItem title="Inventory" systemImage="shippingbox" action="inventory" />
13+
<MenuItem title="End session" systemImage="xmark.circle" action="close" />
14+
</Menu>
15+
<GlassEffect style="regular" cornerRadius="26" maxWidth="infinity">
16+
<HStack paddingLeading="16" paddingTrailing="5" spacing="8" minHeight="52">
17+
<TextField ref="input" placeholder="What do you want to do?" style="plain" maxWidth="infinity" onChange="inputChanged" onCommand="inputCommand" />
18+
<% if speechAvailable then %>
19+
<Button ref="dictate" title="" systemImage="mic" symbolSize="22" accessibilityLabel="Dictate command" action="dictate" style="plain" width="38" height="44" />
20+
<% end %>
21+
<Button ref="send" title="" systemImage="arrow.up" symbolSize="20" accessibilityLabel="Send command" action="submit" style="borderedProminent" width="40" height="40" hidden="<%= speechAvailable and 'true' or 'false' %>" disabled="true" />
22+
</HStack>
23+
</GlassEffect>
24+
</HStack>
25+
</GlassEffectContainer>
2526
</VStack>

‎comparison/iphone_swiftui/build_reference.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ plist -c "Add :CFBundlePackageType string APPL" "$APP/Info.plist"
3333
plist -c "Add :CFBundleShortVersionString string 1" "$APP/Info.plist"
3434
plist -c "Add :CFBundleVersion string 1" "$APP/Info.plist"
3535
plist -c "Add :MinimumOSVersion string 26.5" "$APP/Info.plist"
36+
plist -c "Add :UIStatusBarHidden bool false" "$APP/Info.plist"
3637
plist -c "Add :UIDeviceFamily array" "$APP/Info.plist"
3738
plist -c "Add :UIDeviceFamily:0 integer 1" "$APP/Info.plist"
3839
plist -c "Add :UIApplicationSceneManifest dict" "$APP/Info.plist"

‎comparison/iphone_swiftui/capture.sh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ REFERENCE_ID="org.luaobjc.comparison.swiftui"
1818
LUA_ID="org.luaobjc.host"
1919
PACKAGER_PORT="${PACKAGER_PORT:-18082}"
2020
PACKAGER_URL="http://127.0.0.1:$PACKAGER_PORT"
21+
CAPTURE_SETTLE_SECONDS="${CAPTURE_SETTLE_SECONDS:-6}"
2122
CAPTURE_TMP="$ROOT/build/comparison/iphone_swiftui/captures/ios-26.5-iphone-17"
2223
OUTPUT="$ROOT/comparison/iphone_swiftui/captures/ios-26.5-iphone-17"
2324
mkdir -p "$CAPTURE_TMP"
@@ -70,15 +71,15 @@ for fixture in "$@"; do
7071
sleep 0.5
7172
SIMCTL_CHILD_SWIFTUI_COMPARISON_FIXTURE="$fixture" \
7273
xcrun simctl launch --terminate-running-process "$DEVICE" "$REFERENCE_ID"
73-
sleep 2
74+
sleep "$CAPTURE_SETTLE_SECONDS"
7475
xcrun simctl io "$DEVICE" screenshot "$CAPTURE_TMP/swiftui-$fixture.png"
7576
xcrun simctl launch --terminate-running-process "$DEVICE" com.apple.springboard >/dev/null
7677
sleep 0.5
7778
SIMCTL_CHILD_LUA_OBJC_APP=comparison/iphone_swiftui \
7879
SIMCTL_CHILD_LUA_OBJC_PACKAGER="$PACKAGER_URL" \
7980
SIMCTL_CHILD_LUA_OBJC_COMPARISON_FIXTURE="$fixture" \
8081
xcrun simctl launch --terminate-running-process "$DEVICE" "$LUA_ID"
81-
sleep 2
82+
sleep "$CAPTURE_SETTLE_SECONDS"
8283
xcrun simctl io "$DEVICE" screenshot "$CAPTURE_TMP/lua-objc-$fixture.png"
8384
done
8485

-743 Bytes
Loading
488 Bytes
Loading
12.7 KB
Loading

‎comparison/iphone_swiftui/reference/ComparisonHost.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ private struct ComparisonView: View {
367367
}
368368
.background(Color(uiColor: .systemBackground))
369369
.preferredColorScheme(.light)
370+
.statusBarHidden(false)
370371
.environment(\.locale, Locale(identifier: contract.environment.locale))
371372
.environment(\.layoutDirection, .leftToRight)
372373
.environment(\.dynamicTypeSize, .large)

‎docs/PROJECT_REFERENCE.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ with the native layout direction, and participate in measurement and placement.
392392
navigation titles and Back behavior. Application components must not create a new
393393
window to navigate.
394394

395+
For a pushed UIKit screen that owns the full bottom edge, pass
396+
`{ hidesTabBar = true }` as the third argument to `ns.HostingController(view,
397+
onDisappear, options)` before calling `navigation:push(...)`. This sets the
398+
destination controller's native `hidesBottomBarWhenPushed` property.
399+
395400
For model-driven routes, `require("ui.navigation").Path` stores plain values
396401
and maps each `value.type` to a destination builder. Pass the path and builders
397402
to `NavigationStack { path = path, destinations = { message = function(value)
@@ -703,7 +708,8 @@ ns.Button {
703708

704709
Button `size` and `weight` set the native title font, including in XML:
705710
`<Button title="Applications" style="link" size="11" />`. Omitting them preserves
706-
the standard system button typography.
711+
the standard system button typography. `symbolSize` sets an SF Symbol's point
712+
size independently of title text.
707713

708714
UIKit buttons use the native unbordered system appearance when `style` is
709715
omitted. Set `style="bordered"` or `style="borderedProminent"` when the design
@@ -723,12 +729,25 @@ AppKit also supports `cornerRadius`; UIKit clips the effect view to that radius.
723729
These APIs require macOS 26 or iOS 26. Do not replace them with blur and
724730
opacity layers.
725731

732+
`<GlassEffectContainer spacing="14">` groups nearby glass surfaces using
733+
`NSGlassEffectContainerView` or `UIGlassContainerEffect`, matching SwiftUI's
734+
`GlassEffectContainer`. Its spacing controls when the surfaces begin to merge.
735+
736+
Inside a glass input capsule, use `<TextField style="plain" />` so its native
737+
bezel and background do not draw a second border. The default text field keeps
738+
its platform bezel for standalone use.
739+
726740
```xml
727741
<GlassEffect style="regular" cornerRadius="18">
728742
<VStack padding="16"><Label text="Native glass" /></VStack>
729743
</GlassEffect>
730744
```
731745

746+
`<Menu>` presents native `UIMenu` actions on UIKit and an `NSPopUpButton` menu
747+
on AppKit. Use `systemImage` and `style="glass"` for an icon-only glass trigger;
748+
each `<MenuItem action="name" />` resolves `name` through the template's
749+
`actions` table.
750+
732751
### `UIKit.SpeechRecognizer(callback, locale)`
733752

734753
Creates a microphone dictation session that writes recognition results through
@@ -1422,6 +1441,7 @@ Templates use the `.etlua` extension to reflect that they contain etlua
14221441
| `<TextField>` | `ns.TextField` | `ns.TextField` |
14231442
| `<Button title="…">` | `ns.Button` | `ns.Button` |
14241443
| `<GlassEffect>` | `NSGlassEffectView` | `UIVisualEffectView` + `UIGlassEffect` |
1444+
| `<GlassEffectContainer>` | `NSGlassEffectContainerView` | `UIVisualEffectView` + `UIGlassContainerEffect` |
14251445
| `<VStack>` / `<HStack>` | flex containers | flex containers |
14261446
| `<FlowStack>` | wrapping rows of native views | wrapping rows of native views |
14271447
| `<HSplit>` | `ns.HSplit` (NSSplitView) | — |

0 commit comments

Comments
 (0)