Skip to content
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

TextSpec Do Not Align Correctly When Using YogaAlign.BASELINE #391

Closed
ShouboWang opened this issue Jun 25, 2018 · 3 comments
Closed

TextSpec Do Not Align Correctly When Using YogaAlign.BASELINE #391

ShouboWang opened this issue Jun 25, 2018 · 3 comments

Comments

@ShouboWang
Copy link

Version

master

Issues and Steps to Reproduce

Apply .alignItems(YogaAlign.BASELINE) on a row with 2 Text as child; where one of the Texts have a line break to force two lines.

The two Text are bottom aligned based off the view bottom, rather than baseline aligned:
screen shot 2018-06-21 at 3 53 16 pm

It seems that TextSpec is not using onMeasureBaseline for baseline calculation: (https://github.com/facebook/litho/blob/master/litho-widget/src/main/java/com/facebook/litho/widget/TextSpec.java)

Also, Android LinearLayout should be using baseline alignment as default behavior: https://possiblemobile.com/2013/10/shifty-baseline-alignment/

Expected Behavior

Two texts be baseline aligned:
screen shot 2018-06-25 at 11 10 12 am

Link to Code

package com.facebook.samples.litho.playground;

import android.graphics.Color;

import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.Row;
import com.facebook.litho.annotations.LayoutSpec;
import com.facebook.litho.annotations.OnCreateLayout;
import com.facebook.litho.widget.Text;
import com.facebook.yoga.YogaAlign;

@LayoutSpec
public class PlaygroundComponentSpec {

@OnCreateLayout
static Component onCreateLayout(ComponentContext c) {
return Row.create(c)
.alignItems(YogaAlign.BASELINE)
.child(
Text.create(c)
.textSizeDip(15)
.text("15Test\n asdfg")
.backgroundColor(Color.GRAY)
.build())
.child(Text.create(c).textSizeDip(24).text("24Test").backgroundColor(Color.YELLOW).build())
.build();
}

@passy
Copy link
Member

passy commented Jul 1, 2018

@dsyang Is that the same behaviour you observed?

@dsyang
Copy link
Contributor

dsyang commented Jul 1, 2018 via email

@dsyang
Copy link
Contributor

dsyang commented Jul 1, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants