I want to make a custom implementation of ScrollableTabRow
which allows for a composable element to be displayed 'sticky'ly at the right end of the tab row. But I can't figure out a simple way to extend the functionalities of the default implementation.
Firstly, ScrollableTabRow
is not a class, so I can't really 'extend' it. It is a function, so I will have to duplicate it (and rename it to, say, StickyTabRow
), and then change the logic wherever and however I see fit. However, the problem with this is that the default implementation of ScrollableTabRow
uses several private and internal variables, singleton objects and functions that I cannot access in my own file. So I will need to copy all of these dependencies into StickyTabRow
, and then the dependencies of these dependencies, and so on.
Surely implementing a custom Composable component isn't this difficult? What am I missing here?
Surely implementing a custom Composable component isn't this difficult? What am I missing here?
Most of the time a Composable that contains core Composable and your own logic or or parameter, or combining Modifiers are enough to accomplish your requirements.
Such as creating a Scoped Composable here
https://stackoverflow.com/a/74002236/5457853
or a shake Modifier
Android Compose create shake animation
can be done adding some code instead of copy-pasting whole Rows or Modifier codes.
But, there are cases hat you need to write Composables or Modifiers by copy-pasting source code to update very small part because some params are not exposed to developers.
For instance, to change minimum size a ScrollableTabRow row can have you need to copy paste whole source code to just change so your tabs can have minimum size lower than 90.dp.
private val ScrollableTabRowMinimumTabWidth = 90.dp
as here.
https://stackoverflow.com/a/76533630/5457853
Or when you need an Image composable that returns bounds of drawable area other than black lines you need to rewrite it from scratch.
https://github.com/SmartToolFactory/Compose-Image
Or a Slider that you can add custom thumb, it was re-written for Material3 but in M2 version it's not available. So you need to rewrite it from scratch.
Also there is no click, transform drag modifier that lets you not consume or change propagation direction. So in such a case you need to rewrite source code as here. Transform gestures also don't return when gestures started or ended.
https://stackoverflow.com/a/76021552/5457853
or here
https://stackoverflow.com/a/70847531/5457853
There can be many examples you might need to copy-paste a Composable or a Modifier but compared the situations you can use default composables or Modifiers these are not that a lot.
If it's some parameter that you need that is not exposed and there is no other way to change it via Constraints, size Modifier, other Modifiers or wrapping it inside another Composable your option is to copy-paste source code and change where it needs changes.
But good thing is most of the Composable components are pretty straightforwards, except LazyLists, and easy to do modification after copy-pasting.