SwiftUIKit / Marquee

A powerful implementation of Marquee(scrolling text or label) in SwiftUI, which supports any content view, including text(label), image, video, etc.
MIT License
72 stars 20 forks source link

vertical alignment does not appear to be fixed #1

Closed ClmnsRck closed 3 years ago

ClmnsRck commented 3 years ago

I have this code:

VStack(alignment: .leading) {
                Marquee {
                    Text("Tag \(viewModel.courseDay.indexRank) - \(viewModel.courseDay.title ?? "KEIN TITEL GEGEBEN!")") //TODO: add marqueeText to entire app
                        .font(.headline)
                        .fontWeight(.semibold)
                        .foregroundColor(.primary)
                }.marqueeDuration(9)

                Text(viewModel.courseDay.description ?? "")
                    .font(.body)
                    .fontWeight(.light)
                    .foregroundColor(.secondary)
            }
            .padding(.all, 16)

This however causes the text to be shifted downwards ...

Screenshot 2021-05-02 at 11 45 17
CatchZeng commented 3 years ago

I have already tried and found no problems, please provide more information.

Screen Shot 2021-05-07 at 2 32 29 PM

kelada commented 3 years ago

Hi @CatchZeng I've run into this alignment issue when using the .marqueeWhenNotFit(..) modifier (see screenshot below).

image

I'm new to your library so it's possible that I'm using it incorrectly. Any help would be appreciated (see source below).

import SwiftUI
import Marquee

struct ContentView: View {
    var body: some View {
        VStack(alignment: .center) {
            Text("This works")
            Marquee {
                Text("This does not work")
            }
            .frame(height: 20)
            .marqueeWhenNotFit(true)
        }.padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
CatchZeng commented 3 years ago

@kelada For the feature of marqueeWhenNotFit, you can see https://stackoverflow.com/a/65197021/14785930

kelada commented 3 years ago

@kelada For the feature of marqueeWhenNotFit, you can see https://stackoverflow.com/a/65197021/14785930

@CatchZeng thanks for the quick reply. I don't quite understand your answer, as I am aware of what .marqueeWhenNotFit(...) does and am using it for a reason - in my previous comment I'm highlighting that the Marquee does not respect the VStack(alignment: .center) { ... }.

What I am trying to do is centre a Text view when the string fits inside the Marquee, if it doesn't fit, it should animate - the key is that it respects the alignment of the VStack when not animating.

I've been looking into seeing if I can work around this by using an .alignmentGuide(...) modifier, but the behaviour is very inconsistent. https://swiftui-lab.com/alignment-guides/

CatchZeng commented 3 years ago

@kelada For the feature of marqueeWhenNotFit, you can see https://stackoverflow.com/a/65197021/14785930

@CatchZeng thanks for the quick reply. I don't quite understand your answer, as I am aware of what .marqueeWhenNotFit(...) does and am using it for a reason - in my previous comment I'm highlighting that the Marquee does not respect the VStack(alignment: .center) { ... }.

What I am trying to do is centre a Text view when the string fits inside the Marquee, if it doesn't fit, it should animate - the key is that it respects the alignment of the VStack when not animating.

I've been looking into seeing if I can work around this by using an .alignmentGuide(...) modifier, but the behaviour is very inconsistent. https://swiftui-lab.com/alignment-guides/

Is the picture shown below what you want?

marquee

You can upgrade marqueue to 0.3.0 and try the code below.

        VStack(alignment: .center) {
            Text("This works")
            Marquee {
                Text("This also works")
                    .background(Color.yellow)
            }.background(Color.blue)
            .frame(height: 20)
            // This is the key point.
            .marqueeIdleAlignment(.center)
            .marqueeWhenNotFit(true)
        }.padding()
kelada commented 3 years ago

@CatchZeng that's perfect! thank you so much! 🥇