Post

Replies

Boosts

Views

Activity

swiftui offset of scrollable tab is initialized when tab is converting
Hello, Everyone, I'm developing ios app and have a question. one case that screen of my app has multiple tab including each scrollview, when I change tab scroll offset is initialized. "Search.Tag" is identifiable and id is different each. and FeedListModel is identifiable also. what's the problem, please give me a tip. This is my screenshot and codes. TabView(selection: $model.selected) { ForEach(model.listByTag, id: \.key) { (tag, list) in SearchMoreTab( model: model, feedList: list, tag: tag, stickyHeaderHeight: $stickyHeaderHeight, defaultStickyHeaderHeight: defaultStickyHeaderHeight) .tag(tag) } struct SearchMoreTab: View { @ObservedObject var model: SearchMoreModel @ObservedObject var feedList: FeedListModel let tag: Search.Tag @Binding var stickyHeaderHeight: Float let defaultStickyHeaderHeight: Float // scrollableHeight = contentHeight - scrollViewHeight @State var lastScrollOffset: CGFloat = .zero @State var scrollOffset: CGFloat = .zero @State var contentHeight: CGFloat = .zero @State var scrollHeight: CGFloat = .zero var body: some View { ScrollView { VStack(spacing: 0) { let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2) LazyVGrid(columns: columns) { ForEach(feedList.feeds) { feed in FeedCell(count: 2, spacing: 2, padding: 16, feed: feed) .onAppear { feedList.onAppear(feed) } } } } .padding(.horizontal, 10) .scrollOffsetGetter($scrollOffset, coordinateId: tag.id) .heightGetter($contentHeight) } .coordinateSpace(name: tag.id) .heightGetter($scrollHeight) #if DEBUG .overlay { VStack { Text("scrollable: \(Int(contentHeight - scrollHeight))") Text("offset \(Int(scrollOffset))") } .background(.mint) .allowsHitTesting(false) } #endif .refreshable { Task { try await feedList.populate() } } .onChange(of: scrollOffset) { offset in let scrollableHeight = contentHeight - scrollHeight guard Float(scrollableHeight) > stickyHeaderHeight else { return } if offset < 0 { return } if offset > scrollableHeight { return } guard model.selected == tag else { return } let diff = Float(lastScrollOffset - offset) self.lastScrollOffset = offset stickyHeaderHeight = (stickyHeaderHeight + diff).clamped(to: 0...defaultStickyHeaderHeight) } .onLoad { Task { try await feedList.populate() } } } }
0
0
1k
Aug ’23
Asynchronous Video Encoding using Tencent SDK
Hello, developers and expert, trying to implement encoding video simply using tencent sdk but I got error, and continuation doesn't return any progress or result. anyone help me please... what i am missing? SWIFT TASK CONTINUATION MISUSE: generateVideo(_:) leaked its continuation! 2023-03-30 12:07:15.694914+0900 Metacellar (dev)[87044:19556775] SWIFT TASK CONTINUATION MISUSE: generateVideo(_:) leaked its continuation! func encodeVideo() async throws { if let video { let encoded = try await TencentVideoEncoder.generateVideo(video) } } import TXLiteAVSDK_Professional class TencentVideoEncoder: NSObject { static func generateVideo(_ original: AVAsset) async throws -> AVAsset { let inputPath = try await Cache.saveToLocal( asset: original, cache: Cache.temporary, cacheKey: UUID().uuidString) let outputPath = MetaCellarCache.temporary.cachePath(forKey: UUID().uuidString)! let editor = TXVideoEditer() editor.setVideoBitrate(2300) editor.setVideoPath(inputPath) editor.setCutFromTime(0, toTime: 10) return try await withCheckedThrowingContinuation { continuation in let listener = Listener(onComplete: { result in switch result.retCode { case .GENERATE_RESULT_OK: continuation.resume(returning: AVAsset(url: URL(fileURLWithPath: outputPath))) default: continuation.resume(throwing: NSError(domain: "Encoding Failed", code: result.retCode.rawValue)) } }, onProgress: { progress in print(progress) }) editor.generateDelegate = listener editor.generateVideo(withTwoPass: .VIDEO_COMPRESSED_720P, videoOutputPath: outputPath) } } class Listener: NSObject, TXVideoGenerateListener { private var onComplete: (TXGenerateResult) -> () private var onProgress: (Float) -> () init(onComplete: @escaping (TXGenerateResult) -> (), onProgress: @escaping (Float) -> ()) { self.onComplete = onComplete self.onProgress = onProgress } func onGenerateComplete(_ result: TXGenerateResult) { onComplete(result) } func onGenerateProgress(_ progress: Float) { onProgress(progress) } } }
0
0
789
Mar ’23
swiftui offset of scrollable tab is initialized when tab is converting
Hello, Everyone, I'm developing ios app and have a question. one case that screen of my app has multiple tab including each scrollview, when I change tab scroll offset is initialized. "Search.Tag" is identifiable and id is different each. and FeedListModel is identifiable also. what's the problem, please give me a tip. This is my screenshot and codes. TabView(selection: $model.selected) { ForEach(model.listByTag, id: \.key) { (tag, list) in SearchMoreTab( model: model, feedList: list, tag: tag, stickyHeaderHeight: $stickyHeaderHeight, defaultStickyHeaderHeight: defaultStickyHeaderHeight) .tag(tag) } struct SearchMoreTab: View { @ObservedObject var model: SearchMoreModel @ObservedObject var feedList: FeedListModel let tag: Search.Tag @Binding var stickyHeaderHeight: Float let defaultStickyHeaderHeight: Float // scrollableHeight = contentHeight - scrollViewHeight @State var lastScrollOffset: CGFloat = .zero @State var scrollOffset: CGFloat = .zero @State var contentHeight: CGFloat = .zero @State var scrollHeight: CGFloat = .zero var body: some View { ScrollView { VStack(spacing: 0) { let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2) LazyVGrid(columns: columns) { ForEach(feedList.feeds) { feed in FeedCell(count: 2, spacing: 2, padding: 16, feed: feed) .onAppear { feedList.onAppear(feed) } } } } .padding(.horizontal, 10) .scrollOffsetGetter($scrollOffset, coordinateId: tag.id) .heightGetter($contentHeight) } .coordinateSpace(name: tag.id) .heightGetter($scrollHeight) #if DEBUG .overlay { VStack { Text("scrollable: \(Int(contentHeight - scrollHeight))") Text("offset \(Int(scrollOffset))") } .background(.mint) .allowsHitTesting(false) } #endif .refreshable { Task { try await feedList.populate() } } .onChange(of: scrollOffset) { offset in let scrollableHeight = contentHeight - scrollHeight guard Float(scrollableHeight) > stickyHeaderHeight else { return } if offset < 0 { return } if offset > scrollableHeight { return } guard model.selected == tag else { return } let diff = Float(lastScrollOffset - offset) self.lastScrollOffset = offset stickyHeaderHeight = (stickyHeaderHeight + diff).clamped(to: 0...defaultStickyHeaderHeight) } .onLoad { Task { try await feedList.populate() } } } }
Replies
0
Boosts
0
Views
1k
Activity
Aug ’23
Asynchronous Video Encoding using Tencent SDK
Hello, developers and expert, trying to implement encoding video simply using tencent sdk but I got error, and continuation doesn't return any progress or result. anyone help me please... what i am missing? SWIFT TASK CONTINUATION MISUSE: generateVideo(_:) leaked its continuation! 2023-03-30 12:07:15.694914+0900 Metacellar (dev)[87044:19556775] SWIFT TASK CONTINUATION MISUSE: generateVideo(_:) leaked its continuation! func encodeVideo() async throws { if let video { let encoded = try await TencentVideoEncoder.generateVideo(video) } } import TXLiteAVSDK_Professional class TencentVideoEncoder: NSObject { static func generateVideo(_ original: AVAsset) async throws -> AVAsset { let inputPath = try await Cache.saveToLocal( asset: original, cache: Cache.temporary, cacheKey: UUID().uuidString) let outputPath = MetaCellarCache.temporary.cachePath(forKey: UUID().uuidString)! let editor = TXVideoEditer() editor.setVideoBitrate(2300) editor.setVideoPath(inputPath) editor.setCutFromTime(0, toTime: 10) return try await withCheckedThrowingContinuation { continuation in let listener = Listener(onComplete: { result in switch result.retCode { case .GENERATE_RESULT_OK: continuation.resume(returning: AVAsset(url: URL(fileURLWithPath: outputPath))) default: continuation.resume(throwing: NSError(domain: "Encoding Failed", code: result.retCode.rawValue)) } }, onProgress: { progress in print(progress) }) editor.generateDelegate = listener editor.generateVideo(withTwoPass: .VIDEO_COMPRESSED_720P, videoOutputPath: outputPath) } } class Listener: NSObject, TXVideoGenerateListener { private var onComplete: (TXGenerateResult) -> () private var onProgress: (Float) -> () init(onComplete: @escaping (TXGenerateResult) -> (), onProgress: @escaping (Float) -> ()) { self.onComplete = onComplete self.onProgress = onProgress } func onGenerateComplete(_ result: TXGenerateResult) { onComplete(result) } func onGenerateProgress(_ progress: Float) { onProgress(progress) } } }
Replies
0
Boosts
0
Views
789
Activity
Mar ’23