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

Unable to run a ForEach loop into it #9

Open nameHabbo opened 6 months ago

nameHabbo commented 6 months ago

Been looking for something like this for ages tonight but ive found an annoying bug? when I run the ForEach with the code below the marquee restarts the instant the first text hits the edge of the frame.

Im trying to create a Marquee of game resutls but the second the edge of the first one hits the edge of the box it restarts the loop.

Marquee { HStack{ ForEach(function.lastTen(), id: \.matchRecord.id) {index in HStack { Text("\(function.playerName(for: index.matchRecord.playerId))") Text("VS") Text("\(index.winnerName)") Image(systemName: "trophy.fill") } .padding(.trailing, 50) .font(.system(size: 20)) .foregroundColor(.white) } } } .frame(width: 200, height: 50) .background(Color.mint.opacity(0.8)) .marqueeDuration(duration)

If I run the code below without the external HStack however it loops round perfectlly like expected, but now my ForEach loop is displaying stacked ontop of each other not horizontally.

stonko1994 commented 6 months ago

Hi @nameHabbo,

I had a look at this issue but was not able to reproduce it on my end 🤔

I'm doing something very similar in one of my apps, and it works fine. Could you share additional context or maybe also a little screen recording of the behaviour?


This is what I'm doing in my app:

Marquee {
    HStack {
        Text("(")
            .fontWeight(.regular)
            .foregroundColor(Color(UIColor.label))
        HStack(spacing: 30) {
            ForEach(regularPeriodScores, id: \.index) { periodScore in
                Text(periodScore.scoreInformation)
                    .tracking(10)
                    .fontWeight(.regular)
                    .foregroundColor(periodScore.isActive ? .appBlue : periodScore.isFinished ? .appRed : Color(UIColor.label))
            }
        }
        Text(")")
            .fontWeight(.regular)
            .foregroundColor(Color(UIColor.label))
    }
}
.frame(width: 200, height: 50)
.marqueeDuration(5)
.marqueeDelay(2)
.marqueeAutoreverses(true)
.marqueeWhenNotFit(true)
.marqueeBoundary(.inner)
.marqueeIdleAlignment(.center)

and this is how it looks:

ezgif com-video-to-gif-converter

I also tried to use a HStack inside the ForEach with multiple Text as you have it but it still worked as expected. Are you using Marquee from my fork or from this repo?

nameHabbo commented 6 months ago

Hello @stonko1994 ,

Im gonna try the code you have within my xcode to see if its something im doing wrong or what im trying to inject because even when i was doing a very simple ForEach loop i was still getting the same issue, im also not sure why my code in the above comment looks like i did so trying to upload a video may not have gone well either haha. i will try and get back to you.

im also using the original package, shall i try yours instead??

stonko1994 commented 6 months ago

im also using the original package, shall i try yours instead??

Yes, try my fork from https://github.com/stonko1994/Marquee. It does contain a few fixes and improvements.