Closed kirill-grouchnikov closed 1 month ago
Indeed we're currently providing all the common composition locals only inside the window scope.
I'm not sure whether this should be considered a bug or a feature request.
Another example where this is needed outside of the window scope.
The recently added functions in TextPainter to draw text in a multiplatform way require either TextMeasurer
or TextLayoutResult
. The later needs FontFamily.Resolver to be created. So in both cases, in order to use DrawScope.drawText
we need these common composition locals to be available.
A common example of using DrawScope.drawText
outside of the window scope would be to dynamically create things like icons and overlay them with text elements (or dynamically generate icons or images with text elements) for subsequent use as icons on buttons or somewhere else.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Desktop version 1.4.0 on macOS
Run this:
And it crashes with
Why is
LocalFontFamilyResolver.current
crashing in the application scope? And the same forLocalLayoutDirection.current