rajdeep / proton

Purely native and extensible rich text editor for iOS and macOS Catalyst apps
Other
1.27k stars 81 forks source link

SwiftUI UIRepresentable EditorView extends beyond swiftUI view #106

Open santi-g-s opened 3 years ago

santi-g-s commented 3 years ago

I am using Proton with swiftUI through a UIRepresentableView. I am having trouble enabling the scroll functionality when the editor reaches its container size.

I set up my view this way:

struct RepresentableRichTextEditor: UIViewRepresentable {

    @Binding var attributedText: NSAttributedString

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    let commandExecutor = EditorCommandExecutor()

    func makeUIView(context: Context) -> UIView {

        let editor = EditorView()
        editor.delegate = context.coordinator

        //This forces the editor view to scroll however disables the auto layout provided by the representable view
        //editor.translatesAutoresizingMaskIntoConstraints = false 
        //editor.maxHeight = 300

        EditorViewContext.shared.delegate = context.coordinator
        editor.setFocus()
        return editor
    }

    func updateUIView(_ uiView: UIView, context: Context) {

       //Update logic here

    }
}

I have tried using .frame(height) in the parent SwiftUI View but this didn't seem to affect the underlying editorView.

Does anyone know how to get scrolling working with SwiftUI?

Many thanks

niklasgrewe commented 3 years ago

@santi-g-s could you share your full view setup with Coordinator? How do you make the Binding etc? I am also looking to implement Proton in SwiftUI