-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to InitialValues #39
Conversation
- Deleted the Defaults.kt file, defaults very defined in multiple places: nulls in InitialValues, default method parameters in methods in InitialValues, and initializations where the values are used. Instead, I moved all initial values to InitialValues. Instead of InitialValues being nullable, a default one is always created, and is the single source of truth for initial values. - Removed applyStaticInitialValues since now they are applied directly. - Moved tileSize, workerCount and highFidelityColors to InitialValues. I think it makes sense to have all non-required parameters in the same place, without having to define some in one way and others in another. - Removed the initialValues variable which was being set to null after use. Not it's a function that's being set to null, which feels cleaner to me. - Changed the `return this` in every InitialValues method to using `apply`, which is more idiomatic and cleaner. - Renamed `padding` to `preloadingPadding` to be clearer about what it does (could be confused with `Modifier.padding()`) - Added `rotationEnabled()`, `preloadingPadding()`, and `bitmapFilteringEnabled()` to `InitialValues`. This should make the `MapState` initialization cleaner, because all settings can be set in `InitialValues`, rather than having to mutate it after creation to continue the setup.
Of course feel free to disagree with anything here. : ) |
What's the point of setting |
So instead of: MapState([..], initialValues = InitialValues()[..]).apply {
enableRotation()
} We can just do: MapState([..], initialValues = InitialValues()[..].rotationEnabled(true)) Without the additional setup afterwards. |
Sure, but I find the first one more readable. |
Why not? In my case I have multiple types of maps of the same area, which have slightly different dimensions. So when the user changes the map type, I need to recreate the |
Sorry, I forgot just one word. I meant "we don't need it to set an initial value for the rotation". |
Hmm. Here is my actual code before the changes: MapState(
levelCount = info.zoomLevels,
fullWidth = info.fullWidth,
fullHeight = info.fullHeight,
initialValues = InitialValues()
.scroll(initialPosition.first, initialPosition.second)
.scale(initialScale)
.minimumScaleMode(Fill)
.maxScale(16f)
.tileSize(info.tileSize)
.workerCount(16)
).apply {
enableRotation()
setPreloadingPadding(preloadingPadding)
setBitmapFilteringEnabled { it.scale < 1 }
} And after: MapState(
levelCount = info.zoomLevels,
fullWidth = info.fullWidth,
fullHeight = info.fullHeight,
initialValues = InitialValues()
.scroll(initialPosition.first, initialPosition.second)
.scale(initialScale)
.minimumScaleMode(Fill)
.maxScale(16f)
.tileSize(info.tileSize)
.workerCount(16)
.rotationEnabled(true)
.preloadingPadding(preloadingPadding)
.bitmapFilteringEnabled { it.scale < 1 }
) The second version is more consistent, where in the first version you have to set some attributes in one way, and some change afterwards with an |
Also, the idea of InitValue is to initiate things which can change dynamically. So the tile size is definitely out. |
I thought it was created to not pollute the |
I get your point about readability. But the goal is not for
|
I can see why you don't consider many of these fitting as "initial values". I didn't think of the class as initial values, but as options for creating the |
Yes the naming reflects the intention |
I'm not saying no to the idea of |
I'm going to keep your good ideas about more idiomatic builder pattern, and better initialization. |
Other than that, there's a good news: it's working! And we're getting closer this final |
Well I didn't just push the code without trying to run it first. 😄 |
Please keep this PR open until I'm done (maybe tomorrow) |
Would you then say things like |
|
It's just that creating an object ( |
When some APIs are used for dynamic behavior, and aren't actually useful at state construction (such as |
Cherry-picked your commit on top. |
Or what you did. 😄 |
That's a bit hacky but that works! |
One could argue adding a commit is less hacky than rewriting history. :) |
By "hacky" I meant why I did ;) |
InitialValues
, default method parameters in methods inInitialValues
, and initializations where the values are used. Instead, I moved all initial values toInitialValues
. Instead ofInitialValues
being nullable, a default one is always created, and is the single source of truth for initial values.applyStaticInitialValues()
since now they are applied directly.tileSize
,workerCount
andhighFidelityColors
toInitialValues
. I think it makes sense to have all non-required parameters in the same place, without having to define some in one way and others in another.initialValues
variable which was being set to null after use. Now it's a function that disables itself.return this
in everyInitialValues
method to usingapply
, which is more idiomatic and cleaner.padding
topreloadingPadding
to be clearer about what it does (could be confused withModifier.padding()
)rotationEnabled()
,preloadingPadding()
, andbitmapFilteringEnabled()
toInitialValues
. This should make theMapState
initialization cleaner, because all settings can be set inInitialValues
, rather than having to mutate it after creation to continue the setup.