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

Text kit 2 bug background #211

Open
kissmaxvic opened this issue Oct 31, 2024 · 0 comments
Open

Text kit 2 bug background #211

kissmaxvic opened this issue Oct 31, 2024 · 0 comments

Comments

@kissmaxvic
Copy link

When I show and close the RichTextEditor view several times, an error appears: the background becomes white or black (depending on the device’s theme).

There’s also always an error indicating that text kit 1 is being used, and in that case, everything works fine (no background errors), but as soon as the error disappears, the background turns white or black.

The error under which everything works, funny as it may sound:

Снимок экрана 2024-10-31 в 05 02 01

Display:
ScreenRecording_10-31-2024-06-15-16_1

Code:
VStack {
FcomFctm(stuck: stuck)
TextEditorKit(text: stuck.textRussian, height: stuck.textRusHeight, rusOrNo: true)

         if stuck.textOriginBool.wrappedValue {
                 TextEditorKit(text: stuck.textOrigin, height: stuck.textOriginHeight, rusOrNo: false)
          }

}

import SwiftUI
import RichTextKit

struct TextEditorKit: View {

@StateObject var context: RichTextContext = RichTextContext()


@Binding var text: NSAttributedString

// height of texteditro
@Binding var height: Double
@State var rusOrNo: Bool

@State private var isInspectorPresented = false

@State var dragEnded: Double = 0.0




var body: some View {
    VStack(spacing: 0) {
        ZStack {
            RoundedRectangle(cornerRadius: 20)
                .foregroundColor(rusOrNo ? .textBackground : .textBackgroundYellow)

#if os(macOS)
RichTextFormat.Toolbar(context: context)
#endif
RichTextEditor(
text: $text,
context: context
)
{
if $0.richText.string.isEmpty {
if rusOrNo {
$0.pasteText("Текст", at: 0)
} else {
$0.pasteText("Text", at: 0)
}
$0.textContentInset = CGSize(width: 10, height: 10)
$0.setRichTextColor(.foreground, to: .white, at: NSRange(location: 0, length: 5))
}
}

            .richTextEditorConfig(
                RichTextEditorConfig(isScrollingEnabled: true)
            )
            .richTextEditorStyle(RichTextEditorStyle(fontColor: .white))
            
            
            // Use this to just view the text:
            // RichTextViewer(document.text)

#if os(iOS)
// RichTextKeyboardToolbar(
// context: context,
// leadingButtons: { $0 },
// trailingButtons: { $0 },
// formatSheet: { $0 }
// )
#endif
}
.frame(height: 35 + height)
.toolbar {
ToolbarItem(placement: .automatic) {
Toggle(isOn: $isInspectorPresented) {
Image.richTextFormatBrush
.resizable()
.aspectRatio(1, contentMode: .fit)
}
}
}

        .focusedValue(\.richTextContext, context)
        .richTextFormatSheetConfig(.init(colorPickers: colorPickers))
        .richTextFormatSidebarConfig(
            .init(
                colorPickers: colorPickers,
                fontPicker: isMac
            )
        )
        .richTextFormatToolbarConfig(.init(colorPickers: []))
        .viewDebug()
        ZStack {
            Path { path in
                path.move(to: CGPoint(x: -50, y: 0))
                path.addCurve(to: CGPoint(x: 0, y: 20), control1: CGPoint(x: -20, y: 2), control2: CGPoint(x: -30, y: 20))
                path.addCurve(to: CGPoint(x: 50, y: 0), control1: CGPoint(x: 30, y: 20), control2: CGPoint(x: 20, y: 2))
            }
            .foregroundColor(rusOrNo ? .textBackground : .textBackgroundYellow)
            .frame(width: 1)
            Image(systemName: "arrow.up.and.down")
                .resizable()
                .foregroundColor(.white)
                .frame(width: 5, height: 10)
        }
        .frame(width: 50)
        .gesture(
            DragGesture()
                .onChanged { gesture in
                    // Обновляем смещение
                    height = gesture.translation.height + dragEnded
                }
                .onEnded { _ in
                    if height < 0 {
                        height = 0.0
                    }
                    dragEnded = height
                }
        )
        
    }
    .animation(.spring(), value: height)
    .frame(height: 35 + height + 20)
    .onTapGesture(perform: {
        print(rusOrNo)
    })
    .background(.clear)
    .foregroundColor(.clear)
}

}


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