Skip to content

Commit

Permalink
Merge pull request airbnb#1138 from airbnb/btw/lineHeight
Browse files Browse the repository at this point in the history
Fix issue with Text Layer Anchor Points
  • Loading branch information
buba447 committed Mar 3, 2020
2 parents 8f81de8 + 6d91cbe commit 934954c
Showing 1 changed file with 3 additions and 16 deletions.
Expand Up @@ -52,8 +52,6 @@ final class TextCompositionLayer: CompositionLayer {

let rootNode: TextAnimatorNode?
let textDocument: KeyframeInterpolator<TextDocument>?
let interpolatableAnchorPoint: KeyframeInterpolator<Vector3D>?
let interpolatableScale: KeyframeInterpolator<Vector3D>?

let textLayer: DisabledTextLayer = DisabledTextLayer()
let textStrokeLayer: DisabledTextLayer = DisabledTextLayer()
Expand All @@ -69,11 +67,6 @@ final class TextCompositionLayer: CompositionLayer {

self.textProvider = textProvider

// TODO: this has to be somewhere that can be interpolated
// TODO: look for inspiration from other composite layer
self.interpolatableAnchorPoint = KeyframeInterpolator(keyframes: textLayer.transform.anchorPoint.keyframes)
self.interpolatableScale = KeyframeInterpolator(keyframes: textLayer.transform.scale.keyframes)

super.init(layer: textLayer, size: .zero)
contentsLayer.addSublayer(self.textLayer)
contentsLayer.addSublayer(self.textStrokeLayer)
Expand All @@ -97,9 +90,6 @@ final class TextCompositionLayer: CompositionLayer {

self.textProvider = DefaultTextProvider()

self.interpolatableAnchorPoint = nil
self.interpolatableScale = nil

super.init(layer: layer)
}

Expand All @@ -114,9 +104,7 @@ final class TextCompositionLayer: CompositionLayer {
guard documentUpdate == true || animatorUpdate == true else { return }

let text = textDocument.value(frame: frame) as! TextDocument
let anchorPoint = interpolatableAnchorPoint?.value(frame: frame) as! Vector3D

interpolatableScale?.value(frame: frame)

rootNode?.rebuildOutputs(frame: frame)

let fillColor = rootNode?.textOutputNode.fillColor ?? text.fillColorData.cgColorValue
Expand Down Expand Up @@ -176,9 +164,8 @@ final class TextCompositionLayer: CompositionLayer {
case .center:
textAnchor = CGPoint(x: size.width * 0.5, y: baselinePosition)
}
let anchor = textAnchor + anchorPoint.pointValue
let normalizedAnchor = CGPoint(x: anchor.x.remap(fromLow: 0, fromHigh: size.width, toLow: 0, toHigh: 1),
y: anchor.y.remap(fromLow: 0, fromHigh: size.height, toLow: 0, toHigh: 1))
let normalizedAnchor = CGPoint(x: textAnchor.x.remap(fromLow: 0, fromHigh: size.width, toLow: 0, toHigh: 1),
y: textAnchor.y.remap(fromLow: 0, fromHigh: size.height, toLow: 0, toHigh: 1))

if textStrokeLayer.isHidden == false {
if text.strokeOverFill ?? false {
Expand Down

0 comments on commit 934954c

Please sign in to comment.