Clean Theming in Compose (You're Doing It Wrong!)

  Рет қаралды 43,045

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 55
@rollebonmarquis7574
@rollebonmarquis7574 Жыл бұрын
If you found things in this video a bit off, in particular, the explanation for the default, I think that might be because some of the explanation were wrong (imho): 1. @6:26 Once you have this: val LocalSpacing = compositionLocalOf( defaultFactory = { Spacing() //Notice this line here. We define a default value for the LocalSpacing. } ) You don't necessarily need the lines: // CompositionLocalProvider( // LocalSpacing provides Spacing() // ) { // // } The last lines enable you to update the value for LocalSpacing or to set it in case one was not set already, but, in this video we already set a default value when we define the CompositionLocal. 2. @9:54 The 2nd explanation as to why not to use LocalComposition - I think he got the documentation wrong. In the documentation when they say that you better have a default value, I think what they mean is this: val LocalSpacing = compositionLocalOf( defaultFactory = { Spacing() /*Notice this line here. We define a default value for the LocalSpacing. Better have some value here, as opposed to throw an exception. */ } ) If you don't have a value here, you need to throw an exception in the default factory. Then, whenever some composable calls LocalSpacing.current, developer needs to make sure that some upper composable does indeed set the value for LocalSpacing via "CompositionLocalProvider(LocalSpacing provides x) { ... }". From the documentation: "... Not providing a default value can cause problems and frustration when creating tests or previewing a composable that uses that CompositionLocal will always require it to be explicitly provided."
@utkubilgin2818
@utkubilgin2818 Жыл бұрын
hello, can you share the document?
@ajailani4
@ajailani4 3 жыл бұрын
This is so cool. I've never known about this customization before until I found this video. Keep on it!
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Glad you like it!
@ramasubramanian3154
@ramasubramanian3154 3 жыл бұрын
Hey Philip. It would be cool if you can a video series going through some open source git projects and explaining the project structure. How the data flow works and all that stuff
@jatinvashisht4293
@jatinvashisht4293 3 жыл бұрын
This is excellent, now I will make such LoacalCompositions for many other values also. Thanks Philipp
@GakisStylianos
@GakisStylianos 3 жыл бұрын
Be super wary about what you're using it for. It's very easy to abuse it and regret it later
@simonsloooow
@simonsloooow 3 жыл бұрын
This is very useful for novices in Compose like me! Thanks Philipp~😘
@jeckonly5853
@jeckonly5853 3 жыл бұрын
Yeah!! I learned a lot from this video!!
@ubersticks
@ubersticks 3 жыл бұрын
Boom! Another great lesson. Thanks, Philipp!
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks you're welcome!
@_Mr_Megh_
@_Mr_Megh_ Жыл бұрын
👉👉Good Morning sir I am from India and whenever I see your video I inspire and wants to become Like you and thanks you are not less than celebrity for us . keep doing ill always support .👈👈
@davidozersky412
@davidozersky412 Жыл бұрын
@7:09. I would like to variations within a theme, for example Button Large, Button Small, Button Expressibve etc. Can you create sub-themes? Also what about custom values that could be used within the context of a more complex composable? Lets say you have a composable built from a textview, a background and a button. Can you match elements with the themes? For example lets say you have a spacer that's between a text and a button; and it could be narrow, wide or huge, and you want to create one style for each. That would mean you would want to have one style, or one base theme and multiple child themes. Can you set something in the theme like textButtonSpacing and then apply it in the composable, while setting in the themes?
@anhlongnghien
@anhlongnghien 3 жыл бұрын
Hi philipp, can you enable subtitle/cc for this video? sorry for my bad english!
@thegreatwarrior4989
@thegreatwarrior4989 3 жыл бұрын
Your content is always special and unique 👍👍👍👍👍👍👍👍👍👍👍👍👍👍
@alij3fer
@alij3fer 3 жыл бұрын
Brother as usual you are creative and distinctive 💯
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thank you so much 😀
@OmarMagdy404
@OmarMagdy404 Жыл бұрын
Wow! Composition Locals = Redux in React and React Native. Thanks a lot bro. 😁 😁 Your videos are awesome. I am watching your videos 24/7 Keep it up. 👍
@marlonlom
@marlonlom Жыл бұрын
00:05:13 ... the same approach applies to tablet and foldables?
@yehiaahmed7047
@yehiaahmed7047 3 жыл бұрын
Super great video as well . I really love such way to provide my themes
@mustafaammar551
@mustafaammar551 3 жыл бұрын
Very cool video thank you bro
@alonshlider4881
@alonshlider4881 2 жыл бұрын
9:15 What about a multi module app? Will creating a MaterialTheme file for each module be a good solution?
@jasalvador
@jasalvador 3 жыл бұрын
Thanks a lot! Great tip.
@Guilo583
@Guilo583 3 жыл бұрын
Thx for the tips
@khalidmohammed7820
@khalidmohammed7820 3 жыл бұрын
Its amazing and very useful, thank you very much
@dmytromarchuk3023
@dmytromarchuk3023 3 жыл бұрын
I just wonder why Spacing is not a part of Material Design concept yet
@KotlinBek
@KotlinBek 2 жыл бұрын
Hey Philip, Great tutorial as usual I want to add my custom colors and I also want them change in dark mode. How can I achieve that? here you showed spacing which doesn't requires modifications in light/dark mode. thanks in advance! :)
@kingcoder7654
@kingcoder7654 3 жыл бұрын
❤️❤️
@ubersticks
@ubersticks Жыл бұрын
Is it bad practice to include the top-level Surface inside the ComposeCustomThemingTheme()? It isn't clear or consistent when to use a top level Surface. MainActivity frequently includes this, but not always. Also in Compose previews you need to wrap your call with ComposeCustomThemingTheme { } but not normally use a Surface() {} too.
@nakeepanpi9349
@nakeepanpi9349 3 жыл бұрын
This is amazing video. So I want you to make video with work manager and android key chain if you could. thank you.
@dreamerslab
@dreamerslab 2 жыл бұрын
Super Cool 👏
@sayyid5416
@sayyid5416 6 ай бұрын
why don't directly use these values from data class like: Spacing().medium ?
@jacobgonzalez4746
@jacobgonzalez4746 2 жыл бұрын
Awesome 🚀
@yiyoascen
@yiyoascen 2 жыл бұрын
how do you test for composables properties like background color and style?
@sooshil
@sooshil 2 жыл бұрын
In XML, we put our own custom named colors in both light and night colors.xml file with the same color name. And we call that color from code. Light and Dark colors are automatically handled. How can we achieve that in compose? I only see predefined color sets like.. primary, onPrimary etc. but how can we add our own.. myOwnColor and define two values for light and dark theme? Do we always need to call isSystemInDarkTheme and assign two different colors from every composable?
@7xFuryPlayz
@7xFuryPlayz Жыл бұрын
sir you can change it according to your needs, but first you should know that which pre-defined color names represnts which surface or you can say (compose) in the app , like , primary represents the topbar color , , onprimary represents the color of things present on the topbar, like options menu , title of your app r screen on topbar , and if you might wonder how would you know that , which color represents which ,surface then jst open the default implementation of the compose you are using , and you can see that which default , style or color that compose uses , so just change your style or color for that specific pre-defined color or style in the theme,
@ashwithchandra2622
@ashwithchandra2622 2 жыл бұрын
Bro can you tell me how to extend the scaffold body above and below because it is covering only some part its not covering navigation buttons and also notification bar in OS
@chetangarg9642
@chetangarg9642 3 жыл бұрын
Hi @Phillipp great content !, you have initialized Spacing two times, 1st in local composition and 2nd time in values of CompositionLocalProvider, You will have two different instances. isnt this a bug?
@JamesBond-mq7pd
@JamesBond-mq7pd 2 жыл бұрын
Thank U
@vahidgarousi5064
@vahidgarousi5064 3 жыл бұрын
so cool 😍
@shivamsethi3829
@shivamsethi3829 3 жыл бұрын
Amazing how similar it is to react context
@aryanvikash1967
@aryanvikash1967 2 жыл бұрын
How can we use a linear gradient color In theme
@Joe-yu9wc
@Joe-yu9wc 3 жыл бұрын
do you have higher level course about compose in clean architecture.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Will come out towards the end of this month 👌
@DeceptiveRealities
@DeceptiveRealities Жыл бұрын
I am not sure of why this is an advantage over just providing the values as constants. Spacing is just values that don't change, unlike colours which can be themed. You don't theme spacing.
@heavenlife5619
@heavenlife5619 3 жыл бұрын
*U look like Henry Cevil* 😬
@PhilippLackner
@PhilippLackner 3 жыл бұрын
How often do you want to comment this😂
@tessanix9771
@tessanix9771 Жыл бұрын
how much do you lift at gym?
@TomartStudios
@TomartStudios 2 ай бұрын
bro wtf
@tessanix9771
@tessanix9771 2 ай бұрын
Huh
@VietAndroidDevelopers
@VietAndroidDevelopers 3 жыл бұрын
It is brilliant tips but I don't think different Spacing class for tablet is a good solution. I will come out with my idea that is inherit your video.
@jaspervisser181
@jaspervisser181 Жыл бұрын
why not just create static values? you didn't explained anything
@sanjshe0m
@sanjshe0m 3 жыл бұрын
Somehow I hoped that he would do 69.dp for extraLarge...
@sebastianseno9285
@sebastianseno9285 2 жыл бұрын
why in compose doesn't have Margin? 🫤
Compose Navigation Just Got SO MUCH EASIER 😱
12:00
Philipp Lackner
Рет қаралды 66 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 90 М.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
How to Validate Forms with Clean Architecture (You're Doing it Wrong)
41:08
Full Guide to Jetpack Compose Effect Handlers
24:56
Philipp Lackner
Рет қаралды 101 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 909 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 852 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 85 М.
THIS Compose-State Mistake Leads to Problems In Your Code
7:58
Philipp Lackner
Рет қаралды 47 М.
Make Your Code Clean With the SOLID Principles
18:24
Philipp Lackner
Рет қаралды 102 М.
Compiled Python is FAST
12:57
Doug Mercer
Рет қаралды 123 М.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН