mirror of
				https://github.com/yattee/yattee.git
				synced 2025-11-03 22:22:02 +00:00 
			
		
		
		
	Redraw cells on change of videos
This commit is contained in:
		@@ -9,39 +9,29 @@ struct VideosCellsHorizontal: View {
 | 
			
		||||
    var videos = [Video]()
 | 
			
		||||
 | 
			
		||||
    var body: some View {
 | 
			
		||||
        EmptyView().id("cellsTop")
 | 
			
		||||
 | 
			
		||||
        ScrollViewReader { scrollView in
 | 
			
		||||
            ScrollView(.horizontal, showsIndicators: false) {
 | 
			
		||||
                LazyHStack(spacing: 20) {
 | 
			
		||||
                    ForEach(videos) { video in
 | 
			
		||||
                        VideoView(video: video)
 | 
			
		||||
                            .environment(\.horizontalCells, true)
 | 
			
		||||
                        #if os(tvOS)
 | 
			
		||||
                            .frame(width: 580)
 | 
			
		||||
                            .padding(.trailing, 20)
 | 
			
		||||
                            .padding(.bottom, 40)
 | 
			
		||||
                        #else
 | 
			
		||||
                            .frame(width: 300)
 | 
			
		||||
                        #endif
 | 
			
		||||
                    }
 | 
			
		||||
        ScrollView(.horizontal, showsIndicators: false) {
 | 
			
		||||
            LazyHStack(spacing: 20) {
 | 
			
		||||
                ForEach(videos) { video in
 | 
			
		||||
                    VideoView(video: video)
 | 
			
		||||
                        .environment(\.horizontalCells, true)
 | 
			
		||||
                    #if os(tvOS)
 | 
			
		||||
                        .frame(width: 580)
 | 
			
		||||
                        .padding(.trailing, 20)
 | 
			
		||||
                        .padding(.bottom, 40)
 | 
			
		||||
                    #else
 | 
			
		||||
                        .frame(width: 300)
 | 
			
		||||
                    #endif
 | 
			
		||||
                }
 | 
			
		||||
                #if os(tvOS)
 | 
			
		||||
                    .padding(.horizontal, 40)
 | 
			
		||||
                    .padding(.vertical, 30)
 | 
			
		||||
                #else
 | 
			
		||||
                    .padding(.horizontal, 15)
 | 
			
		||||
                    .padding(.vertical, 20)
 | 
			
		||||
                #endif
 | 
			
		||||
            }
 | 
			
		||||
            .onChange(of: videos) { [videos] newVideos in
 | 
			
		||||
                guard !videos.isEmpty else {
 | 
			
		||||
                    return
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                scrollView.scrollTo("cellsTop", anchor: .leading)
 | 
			
		||||
            }
 | 
			
		||||
            #if os(tvOS)
 | 
			
		||||
                .padding(.horizontal, 40)
 | 
			
		||||
                .padding(.vertical, 30)
 | 
			
		||||
            #else
 | 
			
		||||
                .padding(.horizontal, 15)
 | 
			
		||||
                .padding(.vertical, 20)
 | 
			
		||||
            #endif
 | 
			
		||||
        }
 | 
			
		||||
        .id(UUID())
 | 
			
		||||
        #if os(tvOS)
 | 
			
		||||
            .frame(height: 560)
 | 
			
		||||
        #else
 | 
			
		||||
 
 | 
			
		||||
@@ -9,31 +9,21 @@ struct VideosCellsVertical: View {
 | 
			
		||||
    var videos = [Video]()
 | 
			
		||||
 | 
			
		||||
    var body: some View {
 | 
			
		||||
        EmptyView().id("cellsTop")
 | 
			
		||||
 | 
			
		||||
        ScrollViewReader { scrollView in
 | 
			
		||||
            ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
 | 
			
		||||
                LazyVGrid(columns: items, alignment: .center) {
 | 
			
		||||
                    ForEach(videos) { video in
 | 
			
		||||
                        VideoView(video: video)
 | 
			
		||||
                        #if os(tvOS)
 | 
			
		||||
                            .padding(.horizontal)
 | 
			
		||||
                        #endif
 | 
			
		||||
                    }
 | 
			
		||||
        ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
 | 
			
		||||
            LazyVGrid(columns: items, alignment: .center) {
 | 
			
		||||
                ForEach(videos) { video in
 | 
			
		||||
                    VideoView(video: video)
 | 
			
		||||
                    #if os(tvOS)
 | 
			
		||||
                        .padding(.horizontal)
 | 
			
		||||
                    #endif
 | 
			
		||||
                }
 | 
			
		||||
                .padding()
 | 
			
		||||
            }
 | 
			
		||||
            .onChange(of: videos) { [videos] newVideos in
 | 
			
		||||
                guard !videos.isEmpty else {
 | 
			
		||||
                    return
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                scrollView.scrollTo("cellsTop", anchor: .top)
 | 
			
		||||
            }
 | 
			
		||||
            #if os(tvOS)
 | 
			
		||||
                .padding(.horizontal, 10)
 | 
			
		||||
            #endif
 | 
			
		||||
            .padding()
 | 
			
		||||
        }
 | 
			
		||||
        .id(UUID())
 | 
			
		||||
        #if os(tvOS)
 | 
			
		||||
            .padding(.horizontal, 10)
 | 
			
		||||
        #endif
 | 
			
		||||
        .edgesIgnoringSafeArea(.horizontal)
 | 
			
		||||
        #if os(macOS)
 | 
			
		||||
            .background()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user