There seem to have been lots of questions the last couple days about doing fancy stuff when drawing ...
z
There seem to have been lots of questions the last couple days about doing fancy stuff when drawing inside canvases. I am sure every case is unique, but I wonder how many, if any, are situations where the only reason to use a canvas was because classic Android was too clunky and heavyweight to create custom views, but could be done effectively with compose’s layout system, a couple custom composables, and a custom
Layout
, since there’s relatively so little overhead (both code boilerplate and no giant View class to worry about). In other words, embracing and leveraging compose’s tools instead of trying to work around them. Then problems like how to draw shadows, text, etc would be much simpler because they’d be done using the regular compose APIs.
👏 2
10
c
I never wrote a custom view or layout in the View world, so yeah just doing something as simple as drawing a bezier curve has me confused whether or not I should try to draw it in a canvas, or if theres some compose abstraction on top of that I can use instead.
p
A bit outdated, but I just read this post and have follow up question. What compose components whould you use to create linear chart? Or Bar Chart? I think in those cases the canvas is your only option. Isnt it ?
z
You could basically write a bar chart as a lazy row of bars. The axis labels could be rows/columns maybe with a custom layout depending on how fancy you want your axes to be. Axes themselves might be a draw modifier. The advantage of doing that is your labels and bars could be arbitrary composables.
p
Sure, @Zach Klippenstein (he/him) [MOD], I was thinking exactly the same, but when you check how the track and ticks are done in
Slider
for example, you may start thinking that Canvas is used there for a reason. Also, I have asked similar question before and Adam advised to use Canvas (link: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1615538817009100). Maybe compose is not optimal yet for using in cases of multiple(dozens) repetitions?