Add safeAreaInsets support to all example apps#202
Conversation
commit: |
| // Connect to host | ||
| app.connect(); | ||
| app.connect().then(() => { | ||
| const ctx = app.getHostContext(); |
There was a problem hiding this comment.
Shouldn't this behavior (triggerring the onhostcontextchanged with the initial host context) be part of the connect flow?
There was a problem hiding this comment.
If I understand the code correctly, it merely sets this._hostContext (does not trigger onhostcontextchanged):
Lines 1029 to 1069 in 38126f7
There was a problem hiding this comment.
@jonathanhefner yes, that’s what I meant - I see in the examples that onhostcontextchanged is explicitly triggered from within the connect callback. Do we want this to be part of the connect logic itself in the SDK, rather than requiring developers to remember to call it manually?
There was a problem hiding this comment.
I'm not opposed to that, but my interpretation was that this behavior was intentional — onhostcontextchanged would only be called in response to ui/notifications/host-context-changed.
There was a problem hiding this comment.
Yeah I'd keep its current behaviour to mean explicitly ui/notifications/host-context-changed happened for now.
| app.connect().then(() => { | ||
| const ctx = app.getHostContext(); | ||
| if (ctx) { | ||
| app.onhostcontextchanged(ctx); |
There was a problem hiding this comment.
there is no such getter actually
There was a problem hiding this comment.
Wow, good catch! TIL this is a known limitation of TypeScript: microsoft/TypeScript#295.
I've updated the commit to use an explicit handler function instead.
Apply host-provided safe area insets as padding on main containers across all examples. This ensures content doesn't render under system UI elements like phone notches. React apps use `useState` + `onhostcontextchanged` handler with initial fetch via `getHostContext()` in `useEffect`. Vanilla JS apps apply padding in the handler and invoke it after `connect()`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
79908d8 to
2453b0c
Compare
Merge latest changes from main including: - Vue, Svelte, Preact, and Solid basic server examples (#141) - safeAreaInsets support (#202) - E2E test fixes (#206) - npm publishing for examples (#184) - ui.resourceUri optional (#210) - Method names as consts (#192) - toolInfo.id optional (#216) - PostMessageTransport security fixes (#207, #208) - Server-utils.ts refactoring
Apply host-provided safe area insets as padding on main containers across all examples. This ensures content doesn't render under system UI elements like phone notches.
React apps use
useState+onhostcontextchangedhandler with initial fetch viagetHostContext()inuseEffect. Vanilla JS apps apply padding in the handler and invoke it afterconnect().🤖 Generated with Claude Code