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

YYLayout layoutWithContainer related API issue #1004

Open
Kyle-Ye opened this issue Jun 25, 2024 · 0 comments · May be fixed by #1005
Open

YYLayout layoutWithContainer related API issue #1004

Kyle-Ye opened this issue Jun 25, 2024 · 0 comments · May be fixed by #1005

Comments

@Kyle-Ye
Copy link

Kyle-Ye commented Jun 25, 2024

  1. Swift API issue

On Swift side, the signature of +[YYTextLayout layoutWithContainer:text:] and +[YYTextLayout layoutWithContainers:text:] would both be YYTextLayout.layout(with:text:) automatically.

We need some manually NS_SWIFT_NAME to fix it.

Saying it, it is now will call the +[YYTextLayout layoutWithContainers:text:] API and we should workaround it by using YYTextLayout.layout(with:[container], text: text)[0].

But it will bring out to the issue 2

  1. layoutWithContainers empty array issue

I'll always get an empty array for a valid input. Debugging the source code, it looks like YYTextLayout forgot to add layout into the layouts array.

+ (NSArray *)layoutWithContainers:(NSArray *)containers text:(NSAttributedString *)text range:(NSRange)range {
    if (!containers || !text) return nil;
    if (range.location + range.length > text.length) return nil;
    NSMutableArray *layouts = [NSMutableArray array];
    for (NSUInteger i = 0, max = containers.count; i < max; i++) {
        YYTextContainer *container = containers[i];
        YYTextLayout *layout = [self layoutWithContainer:container text:text range:range];
        if (!layout) return nil;
+       [layouts addObject:layout]; 
        NSInteger length = (NSInteger)range.length - (NSInteger)layout.visibleRange.length;
        if (length <= 0) {
            range.length = 0;
            range.location = text.length;
        } else {
            range.length = length;
            range.location += layout.visibleRange.length;
        }
    }
    return layouts;
}
@Kyle-Ye Kyle-Ye linked a pull request Jun 25, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant