Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASTextNode] slash symbol in string acts like new line symbol #2885

Closed
iwheelbuy opened this issue Jan 10, 2017 · 9 comments
Closed

[ASTextNode] slash symbol in string acts like new line symbol #2885

iwheelbuy opened this issue Jan 10, 2017 · 9 comments

Comments

@iwheelbuy
Copy link

I have some strings to be presented in ASTextNode

Optional("Дом ученых-А/В «Восточный» (Площадка отстоя)")
Optional("А/В «Восточный» (Площадка отстоя)-Дом ученых")
Optional("Площадка для отстоя а/в Восточный-Студенческий городок")
Optional("Студенческий городок-Площадка для отстоя а/в Восточный")

I don't expect a new line right after the / symbol, but the result is:

2017-01-11 0 50 49

Is there a way not to get new line after the /?

The cell code:

func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
    let route: TransportRouteObject? = object(connection: connection, mappings: mappings, indexPath: indexPath)
    let cell = ASCellNode()
    cell.selectionStyle = .none
    cell.backgroundColor = .white
    // text
    let text = ASTextNode()
    text.style.flexGrow = 1.0
    text.style.flexShrink = 1.0
    text.backgroundColor = .orange
    text.style.width = ASDimension(unit: ASDimensionUnit.fraction, value: 1.0)
    text.maximumNumberOfLines = 0
    debugPrint(route?.title)
    let textString = NSAttributedString(
        string: route?.title ?? "Надпись",
        attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 16.0)]
    )
    text.attributedText = textString
    cell.addSubnode(text)
    // code
    let code = ASTextNode()
    code.maximumNumberOfLines = 1
    let codeString = NSAttributedString(
        string: "17",
        attributes: [NSFontAttributeName:UIFont.boldSystemFont(ofSize: 26.0)]
    )
    code.attributedText = codeString
    cell.addSubnode(code)
    //
    cell.layoutSpecBlock = { [unowned text] _ in
        let spec0 = ASStackLayoutSpec(direction: ASStackLayoutDirection.horizontal, spacing: 0, justifyContent: ASStackLayoutJustifyContent.center, alignItems: ASStackLayoutAlignItems.center, children: [code])
        spec0.style.width = ASDimension(unit: ASDimensionUnit.points, value: 60.0)
        let spec1 = ASStackLayoutSpec(direction: ASStackLayoutDirection.horizontal, spacing: 0, justifyContent: ASStackLayoutJustifyContent.start, alignItems: ASStackLayoutAlignItems.center, children: [text])
        spec1.style.flexGrow = 1.0
        spec1.style.flexShrink = 1.0
        let spec2 = ASStackLayoutSpec(direction: ASStackLayoutDirection.horizontal, spacing: 0, justifyContent: ASStackLayoutJustifyContent.start, alignItems: ASStackLayoutAlignItems.center, children: [spec0, spec1])
        return ASInsetLayoutSpec(insets: UIEdgeInsets.init(top: 5.0, left: 0.0, bottom: 5.0, right: 5.0), child: spec2)
    }
    return cell
}
@hannahmbanana
Copy link
Contributor

@iwheelbuy - could you check if this matches the behavior of UILabel?

@iwheelbuy
Copy link
Author

iwheelbuy commented Jan 11, 2017

UILabel is fine

if (route?.title ?? "").contains("ый» (Площадка отстоя)-Дом учен") {
    let label = UILabel.init(frame: UIScreen.main.bounds)
    label.backgroundColor = .white
    label.numberOfLines = 0
    label.text = route?.title
    UIApplication.shared.keyWindow?.addSubview(label)
}

2017-01-11 23 12 28

@iwheelbuy
Copy link
Author

iwheelbuy commented Jan 11, 2017

That is the page I parse information from: http://mu-kgt.ru/informing/wapold/marsh/?t=1
I use String.Encoding.windowsCP1251 to convert from data to string

@hannahmbanana
Copy link
Contributor

@iwheelbuy - would you be willing to create an example project (or modify examples/layoutSpecExamples-Swift/LayoutExampleNode.swift - class HeaderWithRightAndLeftItems) to show this bug? I'm guessing it has something to do with the string encoding which I'm not too familiar with.

@iwheelbuy
Copy link
Author

Sample project is a bit complex, but it shows the issue.
pod install -> run -> tap on "Автобус"

@Jonhory
Copy link

Jonhory commented Mar 17, 2017

Demo show the issue.

@iwheelbuy
Copy link
Author

Jonhory, there is a broken link in your demo readme

@Jonhory
Copy link

Jonhory commented Mar 18, 2017

My Demo update.

UPDATE:

PNG show the issue:

  • Blue backgroundColor is ASTextNode, Red backgroundColor is UILabel

  • I found this issue show when string contains whiteSpace, / , ; ,maybe include more symbols.

Here is my code:

  • loadASTextNode
func loadTextNode(y: CGFloat, with text: String) {
    let textNode = ASTextNode()
    textNode.attributedText = NSAttributedString(string: text,
                                                 attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 16),
                                                              NSForegroundColorAttributeName: UIColor.red])
    textNode.frame = CGRect(x: 100, y: y, width: 200, height: 20)
    textNode.backgroundColor = UIColor.blue
    view.addSubnode(textNode)
}
  • loadUILabel
func loadUILabel(y: CGFloat, with text: String) {
    let label = UILabel()
    label.text = text
    label.textColor = UIColor.blue
    label.backgroundColor = UIColor.red
    label.frame = CGRect(x: 100, y: y, width: 200, height: 20)
    view.addSubview(label)
}

If my code have any question, maybe somebody can help me.Thanks.

@garrettmoon
Copy link
Contributor

This issue was moved to TextureGroup/Texture#173

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

No branches or pull requests

5 participants