Don't Do THIS Jetpack Compose Mistake

  Рет қаралды 19,465

Philipp Lackner

Philipp Lackner

Жыл бұрын

⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses/
💻 Let me be your mentor and become an industry-ready Android developer in 10 weeks:
pl-coding.com/drop-table-ment...
Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!
pl-coding.com/newsletter
Join this channel to get access to perks:
/ @philipplackner
Join my Discord server:
/ discord
Regular programming advice on my Instagram page: / _philipplackner_
Checkout my GitHub: github.com/philipplackner
You like my free content? Here you can buy me a coffee:
www.buymeacoffee.com/philippl...

Пікірлер: 43
@PhilippLackner
@PhilippLackner Жыл бұрын
Because I've read this in many comments now: Of course, putting this as state in the ViewModel works, too (and for filtering I'd honestly also do this myself). But, that doesn't change the fact that doing this is a mistake (I'm often doing code reviews and saw this one very often). Also, there are scenarios where you can't simply put this in the viewmodel, e.g. If you need the context when mapping something to string resources for example.
@maximooze3196
@maximooze3196 Жыл бұрын
Nice vid philipp, I hope you make some shorts about optimizing re-comipistions with "donut scoping", it revolves around the idea of inlining functions
@yossimaskin1393
@yossimaskin1393 Жыл бұрын
I prefer another approach in this case. I prefer preparing those 2 lists in the VM and move logic to there
@meidy3795
@meidy3795 Жыл бұрын
This one of the helpful things i need to do to optimize the apps I build, thanks!
@CodeWithNiks101
@CodeWithNiks101 Жыл бұрын
It was really helpful, thanks for sharing
@tashi7160
@tashi7160 Жыл бұрын
no logic other than a simple if in the ui. let vm drive the state.
@PhilippLackner
@PhilippLackner Жыл бұрын
Yeah with the filter example I chose I'd also probably do that, but there are definitely cases where you can't/shouldn't do this in the ViewModel (imagine mapping something to string resources and you need the context)
@ajailani4
@ajailani4 Жыл бұрын
Agree, because ViewModel acts as a state holder. And I also agree with Philipp, there are another scenarios that we'll be forced to handle the logic in the UI
@kyleMcBurnett
@kyleMcBurnett Жыл бұрын
Thank you so much. Wish I had known this early
@safionweb
@safionweb Жыл бұрын
Amazing video :)
@haykmkrtchyan7093
@haykmkrtchyan7093 4 ай бұрын
Also we can call partition on our list and get both done and undone items list
@JustAmalll
@JustAmalll Жыл бұрын
Hi Phillip, how can i set toolbar color like bootom bar and status bar color like toolbar color ?
@Joe-qv2jo
@Joe-qv2jo Жыл бұрын
Can you pls create a video about libraries android provides and some history about different android version changes as it is difficult for a new developers to know what is new and what is not. Thank you
@Walker32102
@Walker32102 Жыл бұрын
Hey, Philipp. Can you do a video for Rich text editor like most note application, please?
@anudeepananth
@anudeepananth Жыл бұрын
Your expressions in the thumbnail :)
@wagnerarcieri
@wagnerarcieri Жыл бұрын
I would be very happy if your courses could be priced by Region.... In Brazil, 99 euros are equal to half a month of paid work... and been unemployed is tricky
@st4849
@st4849 Жыл бұрын
I'd just have an unmutable list/map of boolean states in the ViewModel that can be accessed/modified via public methods. That way there's no filtering of any sort and only the item(s) that changed will recompose.
@PhilippLackner
@PhilippLackner Жыл бұрын
That's super unflexible and unreadable though
@st4849
@st4849 Жыл бұрын
@@PhilippLackner You clearly prefer to keep the ViewModel clean and I prefer to keep the UI code simple and clean. As that's what you need for best performance. I wouldn't consider doing anything you demonstrated here in my UI code. I thoroughly enjoy watching your videos though and I learned many important things here that I value very much.
@patrickrodriguez4683
@patrickrodriguez4683 Жыл бұрын
Thanks
@carbaj03
@carbaj03 Жыл бұрын
Thank you for sharing this information, it´s very helpful. I think you could take the opportunity to say that this kind of logic shouldn't be in your UI framework.
@PhilippLackner
@PhilippLackner Жыл бұрын
There's no general rule that this shouldn't be in the UI (considering that the VM is also part of the UI). Putting it in the VM solves this as well of course.
@muxtorjonismoilov1647
@muxtorjonismoilov1647 5 ай бұрын
thanks
@fars7346
@fars7346 4 ай бұрын
after applying this my UI loaded more smoothly, cool.
@Alchemist10241
@Alchemist10241 10 ай бұрын
this was exactly what I needed without this I had to recompose a lazy vertical grid in an if else block
@mustafaammar551
@mustafaammar551 Жыл бұрын
very cool you are the best
@mesutemrecelenk5447
@mesutemrecelenk5447 Жыл бұрын
I made every mistake you said don't do it 😂😂😂. Thanks Philipp
@jepp25907
@jepp25907 Жыл бұрын
Really enjoy your videos! I've been doing Android apps as a hobby for a year or so now and your videos have been a great help! Personally, i come from a web-development job so i'm by no means and Android expert. I'm wondering though, stuff like filtering the todos list and generally preparing data for the presentation layer, shouldn't that logic be done in the viewmodel or elsewhere? In my opinion and experience, the UI-layer shouldn't really do any other logic than implementing the UI, and the preparation of data shouldn't be the job of the UI-layer. Again, i'm by no means an app-developer so i'm sure i havent got the best understanding of good app architecture. Would appreciate your thougts on this!
@karmus12
@karmus12 Жыл бұрын
Agree. Filter in the viewmodel and then expose isDone and notDone in state and observe from the ui.
@wagnerarcieri
@wagnerarcieri Жыл бұрын
niceee !
@ChrisAthanas
@ChrisAthanas Жыл бұрын
Please always give the source code link!
@muhmmedalsadig7706
@muhmmedalsadig7706 Жыл бұрын
I think this type of logic should be in vm And your vm avoid recompostion easily
@aliisazadeh6973
@aliisazadeh6973 Жыл бұрын
continue the KMM on youTube please
@oliver_lauritsen_oa
@oliver_lauritsen_oa Жыл бұрын
The whole compose is a mistake!
@cularu1
@cularu1 Жыл бұрын
did you met that Tinder girl?
@PhilippLackner
@PhilippLackner Жыл бұрын
What is tinder
@ayoubkhabib
@ayoubkhabib Жыл бұрын
Roadmap >>>>>> android developer,,,, please?
@dekus80
@dekus80 Жыл бұрын
I think UI must not do and filters, just show. First part no words, somebody do so? (facepalm) and I don't like "correction" with remaining logic in UI too.
@PhilippLackner
@PhilippLackner Жыл бұрын
Debatable :)
@SriHarshaChilakapati
@SriHarshaChilakapati Жыл бұрын
Would love to know your thoughts regarding this: I've been thinking for a while now, but still I'm not fully convinced that Jetpack Compose is actually an improvement compared to existing View system. When we separate the complexity into two ways, API complexity and implementation complexity, I divide them as follows: Android View System - High API Complexity & Medium Implementation Complexity Android View System + LayoutInflater - Low API Complexity & Medium Implementation Complexity Jetpack Compose - Low API Complexity & High Implementation Complexity API Complexity is the complexity of the interface that is exposed to app developers. Here, Compose definitely has got low API complexity, but under the hood, the complexity increases manyfold because one has to understand recompositions and also how the compiler is rewriting the Composables. Just the Android View System has high API complexity (I'd argue it is also medium complexity though) as laying out views in code is not that straight forward, XML actually reduces this to low with the use of LayoutInflater. You define layouts declaratively (one time at the layout, and most views don't simply change their positions anyway unless animated) so declarative UIs are actually achieved. This reminds me constantly that if in case some bug happens in Compose, say there are too many recompositions, or an edge case in animation which is causing another view to displace or change dimensions, people are gonna have to spend even more time trying to identify the cause of it. This, requires people to understand the implementation, which definitely has a high complexity. Would love to know your thoughts. If you think otherwise, I request you to please make a video about this.
@georgemujuru1232
@georgemujuru1232 Жыл бұрын
First
@andrewdunbar828
@andrewdunbar828 8 ай бұрын
Don't Make this English mistake of saying "do a mistake".
@clamum9648
@clamum9648 Жыл бұрын
Say I have a screen with 6 textboxes that the user can enter info into. Normally I'd see this represented as far as saving state by having 6 different state variables, one for each textbox (or really, two variables for each textbox, a private one in the ViewModel and a public one in the ViewModel, that the Composeable can access). Couldn't I also make a single class, like "MyState", that has 6 fields in it, and then manage my screen's state by just referring to that single state variable that my ViewModel now contains? So for example I'd just be referencing MyState.myVarOne, MyState.myVarTwo, ..., MyState.myVarSix rather than myVarOne, myVarTwo, ..., myVarSix. Hopefully that makes sense.
Full Guide to Jetpack Compose Effect Handlers
24:56
Philipp Lackner
Рет қаралды 85 М.
derivedStateOf VS. remember(key) - THIS is Really the Difference 🤯
14:46
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 19 МЛН
Full Guide to Delegation in Kotlin  - Android Studio Tutorial
18:10
Philipp Lackner
Рет қаралды 65 М.
THIS Compose-State Mistake Leads to Problems In Your Code
7:58
Philipp Lackner
Рет қаралды 36 М.
I Made 200 Python Projects...Here Are My 5 FAVORITES
11:23
Tech With Tim
Рет қаралды 122 М.
Type-Safe Navigation with the OFFICIAL Compose Navigation Library
10:03
Lazy layouts in Compose
24:32
Android Developers
Рет қаралды 84 М.
BasicTextField2 - Everything You Need to Know 💻
14:23
Philipp Lackner
Рет қаралды 13 М.
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 19 МЛН