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

Font sizing doesn't work #171

Open
kovs705 opened this issue Apr 25, 2024 · 2 comments
Open

Font sizing doesn't work #171

kovs705 opened this issue Apr 25, 2024 · 2 comments
Labels
discussion Discussions not yet turned into an action

Comments

@kovs705
Copy link

kovs705 commented Apr 25, 2024

  1. Minimum deployment target: iOS 17.0
  2. Physical device and simulator: iOS 17.2
  3. SwiftUI

I'm trying to make a font bigger but I receive strange text in console:

UITextView 0x102839600 is switching to TextKit 1 compatibility mode because its layoutManager was accessed. 
Break on void _UITextViewEnablingCompatibilityMode(UITextView *__strong, BOOL) to debug.

my code:

import SwiftUI
import SwiftData
import RichTextKit

struct NoteView: View {
    
    @State private var context = RichTextContext()
    @State private var attributedNoteText: NSAttributedString
    var note: Note
    
    init(note: Note) {
        self.note = note
        self.attributedNoteText = NSAttributedString(string: note.text)
        
        RichTextEditor.standardRichTextFontSize = 50 // <- I've tried this
        self.context.fontSize = 50  // <- I've tried this
        self.context.isEditable = false // <- I've tried this and editor is still editable (maybe I'm wrong)
    }
    
    var body: some View {
        RichTextEditor(text: $attributedNoteText, context: context) {
            $0.setRichTextFontSize(50) // <- I've tried this
        }
            .focusedValue(\.richTextContext, context)
            .frame(maxWidth: .infinity)
            .frame(minHeight: 100)
            .richTextEditorStyle(.init(font: .preferredFont(forTextStyle: .extraLargeTitle))) // <- I've tried this
    }

result:

@danielsaidi
Copy link
Owner

Hi @kovs705

First of all, the context must be a @StateObject, not @State.

Can you fix that and see if it helps?

@danielsaidi danielsaidi added the discussion Discussions not yet turned into an action label Apr 28, 2024
@kovs705
Copy link
Author

kovs705 commented May 3, 2024

import SwiftUI
import RichTextKit

struct MyView: View {

    @StateObject var context = RichTextContext()
    @State var attributedNoteText: NSAttributedString = NSAttributedString(string: "Test text")

    var body: some View {
        RichTextEditor(text: $attributedNoteText, context: context) {
            $0.setRichTextFontSize(50)
        }
        .focusedValue(\.richTextContext, context)
        .frame(maxWidth: .infinity)
        .frame(minHeight: 100)
        .richTextEditorStyle(.init(font: .preferredFont(forTextStyle: .extraLargeTitle)))
    }
}

#Preview {
    MyView()
}

still small..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussions not yet turned into an action
Projects
None yet
Development

No branches or pull requests

2 participants