Skip to content

Apple TV (tvOS) support - #2411

Draft
TheNoumanDev wants to merge 4 commits into
mainfrom
feat/apple-tv-support
Draft

TheNoumanDev wants to merge 4 commits into
mainfrom
feat/apple-tv-support

Conversation

@TheNoumanDev

Copy link
Copy Markdown
Member

Lets Ensemble apps run on Apple TV (via flutter-tvos), with the same TV behaviour as Android TV. Other platforms are unchanged.

  • Detect Apple TV (isAppleTV) and treat it as a TV.
  • Storage on Apple TV: CDN manifest, GetStorage, asset and image caches go to Caches, since Documents and Application Support aren't writable on hardware.
  • Menu button: tvOS sends it as a system Back, so goBack key handlers first get a key press, as on Android TV (AppleTVBackBridge, installed by the host).
  • TV focus scrolling measures items in the list's own units, so it works when the host scales its UI.
  • On Apple TV the focus engine can't scroll lists through semantics actions (unless VoiceOver is on), and lists clamp instead of bouncing. Also applied to asExternal screens.

Tests added for each change, run for Apple TV and for other platforms. Two TabBar tests (tab_bar_back_focus_test, tab_bar_index_test) already fail on main.

Open: ChartJs needs a WebView, which tvOS doesn't have.

- Add isAppleTV detection and an Apple TV storage directory (Library/Caches,
  falling back to tmp), since Documents isn't writable on hardware.
- Store the CDN manifest (encrypted envelope) in a file on Apple TV instead of
  SharedPreferences, which tvOS aborts on past ~1 MB.
- Create GetStorage boxes in the Apple TV directory.
- Keep the CDN asset cache and the image cache database in the Apple TV
  directory, since Application Support can't be created on hardware.
- Report Apple TV as isTV; add isAndroidTV / isTvOS device getters.
- Skip Workmanager init on Apple TV (no tvOS implementation).
flutter-tvos sends the Siri Remote Menu button only as a system Back
(popRoute), so goBack key handlers never ran on Apple TV. AppleTVBackBridge
first sends a goBack key press (down, then up) through the focus tree; if the
key-up is handled, Menu stops there, otherwise the system Back goes ahead.
This is the same order as on Android TV. Does nothing outside Apple TV; the
host calls install() before runApp.
TV focus scrolling compared screen positions (localToGlobal) with sizes and
scroll offsets. When the host scales its UI, as KPN does on Apple TV (a
960x540 layout drawn 2x), screen positions are scaled and the rest is not,
so visible items looked off-screen: pages jumped and lanes lost their
leading margin. Measure the item in the scrollable's coordinates instead
(rectInScrollable). Unscaled hosts get the same result as before.

The horizontal helpers move from box_wrapper to tv_focus_scroll so they can
be tested; tests run every case at 1x and with a 2x host scale.
flutter-tvos keeps semantics on without VoiceOver, so every scrollable
offers scrollToOffset and showOnScreen, and the focus engine used them while
Ensemble was scrolling the same list: short lanes jerked and pages jumped
past their end. On Apple TV, lists now don't allow implicit scrolling
unless VoiceOver is on, and clamp like Android TV instead of bouncing.
Applied through the MaterialApp scroll behavior, to lists with their own
physics, and to asExternal screens on the host navigator. Other platforms
are unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant