I wanna make my compose app more user friendly on ...
# compose
z
I wanna make my compose app more user friendly on android tv, is there a way to get my UI to layout slightly different, and be able to check in code if it's running on TV so I can show stuff thats not needed on mobile?
đŸ˜¶ 3
a
You'd be better off making a new target for your TV app instead of sharing your mobile app target
And you'd probably want a third target for shared code, like presenters, view models, shared ui elements, networking, etc
Of which could probably be split up more
c
I'm not being too helpful here besides letting you know that TV support is officially alpha as of Monday I think? https://developer.android.com/jetpack/androidx/releases/tv
a
You could technically also use flavors but that's a REALLY messy route.
z
im using compose
forgot to mention that for the 3 not kotlin reactions
a
It’s still more of an architectural question anyway, it could apply to the view system, java, etc
You should structure your project so your mobile and tv apps are separate
You’ll be saving yourself a huge headache checking if your platform is for TV or phone within your shared mobile codebase
z
well theres some composables I dont really need to change at all, I tested and they look fine on both devices
a
And those can go into a separate shared library
your mobile and tv targets would use it to pull shared logic, shared ui elements, etc
but anything platform specific gets implemented separately
c
I don't disagree with Andrew about separate targets but I used to have an app I worked on that worked with a single apk across phone, tabs and tvs and it worked really well. The experience overall was always a big screen first experience (tablets) and so it moved to TV easily. Basically just saying that, its' not the worst thing if it makes sense in your scenario for it to be all in one app
@Alex Vanyo do you know if any of the multi screen stuff has support for detecting if it's a TV? I know there were those window class sizes and I'm wondering if it is meant to work with TVs too
a
The issue arises if you want to use a set of leanback components conditionally, you’re much more equipped when using multiple targets
There are ways to detect if the display is a TV though
c
Yeah. I never used the lean back library.
a
Leanback or leanback-esque components would be crucial to blending in, but as you mentioned isn’t necessarily required. UX might be a little weird though but that is on a per app basis.
i
Working in TV company, we do both mobile and TV, we mostly share all the code as many things are common. Also we are backend driven so lots of things are done on the backend side, and presented easily to the ui (example a grid on TV and a carousel on mobile). So for us it’s easy to not end up in complex flavors or packaging.
z
@andrew would I be able to use expect and actual declarations?
a
Not across multiple targets that aren't multiplatform as it's all JVM/Android
z
I'm not sure how I would make a different implementation for TV, do you have some example I could look at
a
Well for starters, you can abstract away a lot of your common implementation details like networking, any models, database/data retention away from your current app
This would be some kind of core module, and you could probably split this up further
So at that point you might have
:app:mobile
and
:core
under your project’s root
And
:app:mobile
would include
:core
You could also split up any shared primitive custom UI components you might have as well
z
I see
I've already got my networking split into a separate module
a
At that point you could start a separate app target for TV, using the same package id, etc. This project would also include any core/shared modules that are critical to both
So both
:app:mobile
and
:app:tv
would depend on
:core
and maybe a
:core:ui
package for example
Then you could build more “leanback” styled layouts with the guarantee that no mobile only code will ever run, and this target will only run on tv since you’re requiring the hardware for it 🙂
You’re also able to exclude any tv only dependencies like compose for TV from your mobile app
z
What exactly is leanback?
a
message has been deleted
Best example I can find
Looks older, but should convey it still
Just layouts optimized for a TV UX
z
In my gradle config how would I make it build the TV and mobile APK seperate?
a
you need two separate app targets
After everything is separated, you could probably just make a copy of your mobile target and name it tv
Then you need to include it in your settings.gradle file
Afterwards, remove everything, strip it down
At least then any conventions you have in your gradle config, boilerplate, etc still remain
As you can see here, we have mobile and wear
message has been deleted
And each module has been included