Comments (13)
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.
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.
When I switch to the good ol' textViewDidChange delegate method, no crash. It also doesn't crash using UITextField, only UITextView.
from combinecocoa.
Can you attach a repro project to save some time? @kevinrenskers
Thanks
from combinecocoa.
Will do.
from combinecocoa.
from combinecocoa.
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:
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.
But it works with all text just fine, just not emoji.
from combinecocoa.
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.
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.
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.
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.
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.
from combinecocoa.
Related Issues (20)
- Umbrella directory '/Users/freak4pc/Work/OSS/CombineCocoa/Sources/Runtime/include' not found
- Combine Publisher needs back pressure management HOT 4
- `didSelectItemPublisher` from collection view only pushes element to latest subscriber HOT 1
- Only last UITextView subscriber receives events HOT 2
- FeatureRequest: Add handlers for selectors HOT 4
- How to use in `UIImagePickerController`
- UICollectionView Crash when using delegate publishers and UICollectionViewDiffableDataSource
- Combine Cocoa fails to archive with Xcode 13 RC HOT 5
- UIScrollView publishers issue in version 0.4.0 HOT 1
- When using UIScrollViewDelegateProxy and UICollectionViewDelegateProxy, one is ignored HOT 1
- Collection view publishers should not have an effect before subscription
- Failed to build a project with latest version
- Memory Leaks in TapPublisher HOT 3
- UITextField textPublisher emitting twice HOT 4
- can't assign Publisher to Button Tapped Publisher HOT 3
- button can not touch up HOT 1
- button can not touchUpInside
- UICollctionView did not work as expected. When I use colltionView to listen to both didScollPublish and didSelectedItemPublisher
- Using private handleEvent API HOT 10
- tableView(_:viewForHeaderInSection:) delegate method cannot be used HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from combinecocoa.