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

[tvOS] Markdown frame badly positionned in a scrollview #359

Open
3 tasks done
ThomasD013 opened this issue Oct 31, 2024 · 0 comments
Open
3 tasks done

[tvOS] Markdown frame badly positionned in a scrollview #359

ThomasD013 opened this issue Oct 31, 2024 · 0 comments

Comments

@ThomasD013
Copy link

Describe the bug
On tvOS, Markdown view is badly positionned in a scrollview. A part of the view is out of screen.

Checklist

  • I can reproduce this issue with a vanilla SwiftUI project.
  • I can reproduce this issue using the main branch of this package.
  • This bug hasn't been addressed in an existing GitHub issue.

Steps to reproduce

Copy past the code in a basic project with swift-markdown-ui as dependency.
Enable tvOS Support.
Try the 3 options like the video.

Expected behavior
I'm expecting to be able to scroll on a scrollview when i'm putting a markdown element.

Screenshots
https://github.com/user-attachments/assets/cddec0d6-0237-4bd0-9873-85bfee9cd44d

Version information

  • MarkdownUI: 2.3.1
  • OS: tvOS 18
  • Xcode: 16.0

Additional context

import SwiftUI
import MarkdownUI

struct ContentView: View {
    var body: some View {
        // Badly positionned on top
//        Markdown(Constants.basicMarkdown)

        // Goodly positionned on top but don't scroll
//        ScrollView {
//            Markdown(Constants.basicMarkdown)
//        }

        // Badly positionned on top and bot but scroll good
        CustomScrollView {
            Markdown(Constants.basicMarkdown)
        }
    }
}

#Preview {
    ContentView()
}

struct Constants {

    static let basicMarkdown = """
# Analyse Complémentaire 1
Les efforts de vente ont permis d'atteindre les objectifs dans certaines régions malgré quelques difficultés dans d'autres. Un suivi est recommandé dans les régions en baisse pour maintenir la dynamique globale.
# Analyse Complémentaire 2
# Analyse Complémentaire 3
# Analyse Complémentaire 4
# Analyse Complémentaire 5
# Analyse Complémentaire 6
# Analyse Complémentaire 7
# Analyse Complémentaire 8
# Analyse Complémentaire 9
# Analyse Complémentaire 10
# Analyse Complémentaire 11
# Analyse Complémentaire 12
"""
}

struct CustomScrollView<Content: View>: UIViewRepresentable {
    let content: Content

    init(@ViewBuilder content: () -> Content) {
        self.content = content()
    }

    func makeUIView(context: Context) -> UIScrollView {
        let scrollView = UIScrollView()
        scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(integerLiteral: UITouch.TouchType.indirect.rawValue)]

        let hostingController = UIHostingController(rootView: content)
        hostingController.view.translatesAutoresizingMaskIntoConstraints = false
        scrollView.addSubview(hostingController.view)

        NSLayoutConstraint.activate([
            hostingController.view.topAnchor.constraint(equalTo: scrollView.topAnchor),
            hostingController.view.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
            hostingController.view.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
            hostingController.view.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            hostingController.view.widthAnchor.constraint(equalTo: scrollView.widthAnchor)
        ])

        return scrollView
    }

    func updateUIView(_ uiView: UIScrollView, context: Context) {    }
}
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

No branches or pull requests

1 participant