Giter Site home page Giter Site logo

Comments (13)

ZvonimirMedak avatar ZvonimirMedak commented on July 1, 2024 1

With the addition on my PR #73, the example @kevinrenskers provided doesn't crash but you do get a circular dependency, and the app loops since you're saving the values from the textView.textPublisher to another publisher and then assigning the same value to the textView again.
Screenshot 2022-07-07 at 16 01 16
Why the textView.textPublisher gets called after adding an emoji is that the emoji uses a different font and it will send the editingAttributes action to the didProcessEditingRangeChangeInLengthPublisher.

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

When I switch to the good ol' textViewDidChange delegate method, no crash. It also doesn't crash using UITextField, only UITextView.

from combinecocoa.

freak4pc avatar freak4pc commented on July 1, 2024

Can you attach a repro project to save some time? @kevinrenskers
Thanks

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

Will do.

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

CombineCocoaTest.zip

from combinecocoa.

freak4pc avatar freak4pc commented on July 1, 2024

Hey @kevinrenskers - I don't think there's any bug with the library per-se here, since if you replace it with a print, everything works:

image

I think the real problem is that you're introducing reentrancy - you are assigning a value of something that effects that very same value. In this specific case the crash is:

Attempted layout while textStorage is editing. It is not valid to cause the layoutManager to do layout while the textStorage is editing (ie the textStorage has been sent a beginEditing message without a matching endEditing.)

Which seems reasonable (you are editing and writing, e.g. causing a layout at the exact same time or at a timing that causes a reentrancy/race).

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

But it works with all text just fine, just not emoji.

from combinecocoa.

freak4pc avatar freak4pc commented on July 1, 2024

Yup, I imagine drawing grapheme clusters is a different task that requires different handling. Regardless this error comes from NSTextStorage and not from CombineCocoa itself. I'm not too sure if I have an idea for something that could be done here.

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

I wonder if it's something in didProcessEditingRangeChangeInLengthPublisher.

Like I said, if you build the exact same functionality using good old textViewDidChange, it doesn't crash.

import UIKit
import Combine
import CombineCocoa

class SearchViewController: UIViewController {
  @IBOutlet var textView1: UITextView!
  @IBOutlet var textView2: UITextView!

  @Published var value: String? = ""

  private var subscriptions = Set<AnyCancellable>()

  override func viewDidLoad() {
    super.viewDidLoad()

    $value
      .sink {
        self.textView1.text = $0
        self.textView2.text = $0
      }
      .store(in: &subscriptions)
  }
}

extension SearchViewController: UITextViewDelegate {
  func textViewDidChange(_ textView: UITextView) {
    value = textView.text
  }
}

from combinecocoa.

freak4pc avatar freak4pc commented on July 1, 2024

There is nothing reentrant about this code though. I don't think the delegate gets called when the sink hits the .text setter, but it does happen with assign for some reason.

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

So, it's not the assigning that's the problem (I still have the $value.sink code), but reading the value that seems to trip it up - the textPublisher.

from combinecocoa.

kevinrenskers avatar kevinrenskers commented on July 1, 2024

It also doesn't crash if you replace both UITextView with a UITextField, which don't use the didProcessEditingRangeChangeInLengthPublisher, which is why my mind is going in that direction.

from combinecocoa.

freak4pc avatar freak4pc commented on July 1, 2024

from combinecocoa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.