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

Performance fix is selectable #214

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Introduced experimental flags for deferring isSelectable
  • Loading branch information
rajdeep committed Aug 15, 2023
commit 8ff38fd5fd8312c65978dace9ef6aa535ba4ca5f
8 changes: 7 additions & 1 deletion ExampleApp/ExampleApp/MasterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

import UIKit
import Proton

struct Navigation {
let title: String
Expand All @@ -32,7 +33,7 @@ struct NavigationItem {

class MasterViewController: UITableViewController {

let navigation = [
lazy var navigation = [
Navigation(title: "Basic features", items: [
NavigationItem(title: "Autogrowing Editor", viewController: { AutogrowingEditorViewExampleViewController() }),
]),
Expand All @@ -56,6 +57,11 @@ class MasterViewController: UITableViewController {
]),
]

required init?(coder: NSCoder) {
EditorView.experimentalFlags.isDeferredSelectable = true
super.init(coder: coder)
}

override func viewWillAppear(_ animated: Bool) {
clearsSelectionOnViewWillAppear = splitViewController!.isCollapsed
super.viewWillAppear(animated)
Expand Down
4 changes: 4 additions & 0 deletions Proton/Proton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
1B183D8C23CEA90400AE83E5 /* EditorContentEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B183D8B23CEA90400AE83E5 /* EditorContentEncoding.swift */; };
1B183D8E23CEE9BA00AE83E5 /* AttributesEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B183D8D23CEE9BA00AE83E5 /* AttributesEncoding.swift */; };
1B183D9223CEEED900AE83E5 /* EditorContentEncoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B183D9023CEEEC400AE83E5 /* EditorContentEncoderTests.swift */; };
1B1B36372A8B52390084C282 /* Experimental.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B1B36362A8B52390084C282 /* Experimental.swift */; };
1B1C3727244BE0D60028E1ED /* EditorViewContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B1C3726244BE0D60028E1ED /* EditorViewContextTests.swift */; };
1B238D6E2456A40200BF49D5 /* NullRichTextEditorContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B238D6D2456A40200BF49D5 /* NullRichTextEditorContext.swift */; };
1B2BC0D823CF17E300407DEE /* EditorContentTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B2BC0D723CF17E300407DEE /* EditorContentTransformerTests.swift */; };
Expand Down Expand Up @@ -177,6 +178,7 @@
1B183D8B23CEA90400AE83E5 /* EditorContentEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorContentEncoding.swift; sourceTree = "<group>"; };
1B183D8D23CEE9BA00AE83E5 /* AttributesEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributesEncoding.swift; sourceTree = "<group>"; };
1B183D9023CEEEC400AE83E5 /* EditorContentEncoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorContentEncoderTests.swift; sourceTree = "<group>"; };
1B1B36362A8B52390084C282 /* Experimental.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Experimental.swift; sourceTree = "<group>"; };
1B1C3726244BE0D60028E1ED /* EditorViewContextTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorViewContextTests.swift; sourceTree = "<group>"; };
1B238D6D2456A40200BF49D5 /* NullRichTextEditorContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NullRichTextEditorContext.swift; sourceTree = "<group>"; };
1B2BC0D723CF17E300407DEE /* EditorContentTransformerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorContentTransformerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -490,6 +492,7 @@
1B82570C23C5686F0033A0A9 /* EditorViewContext.swift */,
1B8BE91A23C71CEA00353B17 /* EditorViewDelegate.swift */,
1B36192C2A68D89A00323BBF /* AggregateEditorViewDelegate.swift */,
1B1B36362A8B52390084C282 /* Experimental.swift */,
);
path = Editor;
sourceTree = "<group>";
Expand Down Expand Up @@ -1030,6 +1033,7 @@
1B82570923C5674E0033A0A9 /* EditorCommand.swift in Sources */,
1B91E7B926AA698A0002DF45 /* StrikethroughCommand.swift in Sources */,
1B82570D23C5686F0033A0A9 /* EditorViewContext.swift in Sources */,
1B1B36372A8B52390084C282 /* Experimental.swift in Sources */,
1B975AFF23CD454700EC410C /* RichTextViewContext.swift in Sources */,
1B45CDE823C05C0C001EB196 /* Focusable.swift in Sources */,
1B7C76AA2608A489006618AC /* FontTraitToggleCommand.swift in Sources */,
Expand Down
24 changes: 15 additions & 9 deletions Proton/Sources/Swift/Core/RichTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class RichTextView: AutogrowingTextView {
get { richTextStorage.defaultTextFormattingProvider }
set {
richTextStorage.defaultTextFormattingProvider = newValue
typingAttributes[.font] = defaultTypingAttributes[.font]
typingAttributes[.paragraphStyle] = defaultTypingAttributes[.paragraphStyle]
typingAttributes[.foregroundColor] = defaultTypingAttributes[.foregroundColor]
// typingAttributes[.font] = defaultTypingAttributes[.font]
// typingAttributes[.paragraphStyle] = defaultTypingAttributes[.paragraphStyle]
// typingAttributes[.foregroundColor] = defaultTypingAttributes[.foregroundColor]
}
}

Expand Down Expand Up @@ -226,14 +226,19 @@ class RichTextView: AutogrowingTextView {

self.backgroundColor = defaultBackgroundColor
self.textColor = defaultTextColor
self.typingAttributes = defaultTypingAttributes
// self.typingAttributes = defaultTypingAttributes
}

private var _isSelectable = true
// override var isSelectable: Bool {
// get { return _isSelectable }
// set { _isSelectable = newValue }
// }
private var _isSelectable = false
override var isSelectable: Bool {
get { return _isSelectable }
set {
_isSelectable = newValue
if EditorView.experimentalFlags.isDeferredSelectable == false {
super.isSelectable = newValue
}
}
}

var contentLength: Int {
return textStorage.length
Expand Down Expand Up @@ -527,6 +532,7 @@ class RichTextView: AutogrowingTextView {
}

private func enableSelectable() {
guard EditorView.experimentalFlags.isDeferredSelectable else { return }
super.isSelectable = _isSelectable
becomeFirstResponder()
typingAttributes[.font] = defaultTypingAttributes[.font]
Expand Down
3 changes: 3 additions & 0 deletions Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ open class EditorView: UIView {
let context: RichTextViewContext
var needsAsyncTextResolution = false

public static var experimentalFlags = Experimental()


// Holds `attributedText` until Editor move to a window
// Setting attributed text without Editor being fully ready
// causes issues with cached bounds that shows up when rotating the device.
Expand Down
25 changes: 25 additions & 0 deletions Proton/Sources/Swift/Editor/Experimental.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Experimental.swift
// Proton
//
// Created by Rajdeep Kwatra on 15/8/2023.
// Copyright © 2023 Rajdeep Kwatra. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

public struct Experimental {
public var isDeferredSelectable = false
}