-
Notifications
You must be signed in to change notification settings - Fork 248
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
Kotlin migration #19
base: master
Are you sure you want to change the base?
Kotlin migration #19
Conversation
app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt
Outdated
Show resolved
Hide resolved
typeface = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf") | ||
} | ||
|
||
val textDaai = Text.Builder("Daai") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like using Java API from Kotlin, feels a bit verbose. I would expect something more idiomatic to Kotlin (Data classes, type-safe builders, or just apply
with mutable fields as you do earlier?) Maybe any reason for set..
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. I actually tried to get rid of TextBuilder
, but there two problems:
- Making of
Position
instance has it's own requirements and there're 3 most frequent cases and they are hidden in setters:
val position1 = Position(align, alignText = alignText)
val position2 = Position(align)
val position3 = Position(point = PointF(px, py))
- For most cases
scale
andscale pivot
needs to be set correctly and it's done in finalbuild
call:
val text = Text(text, position, padding, paint)
text.scaleX = scale
text.scaleY = scale
text.setScalePivot(scalePivot, scalePivot)
So for most cases Builder
hides these requirements inside setters and final build
function. For custom (and probably very rare cases with weird position and maybe inverted or negative scale) cases developer can use Position
and Text
constructors without Builder
.
But it might be that these requirements can be hidden inside type-safe builder. Need to think about better api.
ScaleValue
andPosition
converted into data classesinvalidate
calls (text reveal animations)Debug
toTextSurfaceDebug
to avoid spoiling namespaceTextBuilder
>Text.Builder
@CallSuper
toTextEffect.onStart
@CallSuper
toSurfaceAnimation.cancel
ScrollView
Fixes It doesn't work if it's in ScrollView #13