Multiple method calls during property updates.
See original GitHub issueProblem:
invalidateViewHolders()
, updateApapterMonthConfig()
and updateAdapterViewConfig()
methods are called multiple times if related properties are set in the CalendarView class.
Proposed solution:
Add an update
method which will not trigger any of the above methods if properties are updated inside it. This way we avoid creating setter methods for all related properties of CalendarView.
Something like this:
open class CalendarView : RecyclerView {
....
private var isUpdating = false
private var pendingAdapterMonthConfigUpdate = false
private var pendingAdapterViewConfigUpdate = false
private var pendingViewHolderInvalidation = false
fun update(block: CalendarView.() -> Unit) {
isUpdating = true
this.block()
isUpdating = false
if (pendingAdapterMonthConfigUpdate) updateAdapterMonthConfig()
if (pendingAdapterViewConfigUpdate) updateAdapterViewConfig()
if (pendingViewHolderInvalidation) invalidateViewHolders()
pendingAdapterMonthConfigUpdate = false
pendingAdapterViewConfigUpdate = false
pendingViewHolderInvalidation = false
}
....
}
Then the update methods will look like:
private fun updateAdapterMonthConfig() {
if (isUpdating) {
pendingAdapterMonthConfigUpdate = true
return
}
....
}
private fun invalidateViewHolders() {
if (isUpdating) {
pendingViewHolderInvalidation = true
return
}
....
}
private fun updateAdapterViewConfig() {
if (isUpdating) {
pendingAdapterViewConfigUpdate = true
return
}
....
}
Now using example 1 where we update a lot of configs, we can write:
animator.doOnStart {
if (!monthToWeek) {
binding.exOneCalendar.update { // No more => exOneCalendar.apply{}
inDateStyle = InDateStyle.ALL_MONTHS
maxRowCount = 6
hasBoundaries = true
}
}
}
Continued from #184
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Method/Function To Update Multiple Properties Per One Control
Just pass the control. Yes; you just need to provide an argument of the appropriate type. For example: static void UpdateProperties(System.
Read more >Is it poor practice to call methods through multiple objects?
The Law of Demeter suggests that you shouldn't call methods on objects two layers down like that. The idea is that, in your...
Read more >Go: Call option that can be used with multiple methods
Go: Call option that can be used with multiple methods. Allow shared options in function and method calls, now with type safety! Photo ......
Read more >Patch function in Power Apps (contains video) - Power Platform
Use the UpdateIf function to modify specific properties of multiple records based on a condition. Modify or create a set of records in...
Read more >Class Constructor Methods - MATLAB & Simulink - MathWorks
You can suppress the assignment of the class instance to the ans variable when no output variable is assigned in a call to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The first one is what I had in mind. However, I think maybe we should start with some of the props that have more obvious groupings like padding, margin, and height/width.
Even doing just those would be a big win I think.
Okay, so I want to start with grouping the methods that directly cause a creating of
MonthConfig
since I want to allow generating the dates in the background.This is what it looks like presently:
Does the method look like what you had in mind? Or were you thinking more in the direction of something like: