Skip to content

Commit

Permalink
Delay updating the Hand-Off message text
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Jun 17, 2021
1 parent 81152ad commit 1d1390b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions IRCCloud/Classes/MainViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
BOOL _ignoreInsetChanges;
NSString *_msgid;
UIView *_leftBorder, *_rightBorder;
NSTimer *_handoffTimer;
}
@property (nonatomic) int cidToOpen;
@property (nonatomic) int bidToOpen;
Expand Down
25 changes: 20 additions & 5 deletions IRCCloud/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2545,15 +2545,29 @@ -(void)expandingTextViewDidChange:(UIExpandingTextView *)expandingTextView {
} else {
[self performSelectorOnMainThread:@selector(scheduleSuggestionsTimer) withObject:nil waitUntilDone:NO];
}
[[self userActivity] setNeedsSave:YES];
[self userActivityWillSave:[self userActivity]];
if(self->_buffer) {
self->_buffer.draft = expandingTextView.text.length ? expandingTextView.text : nil;
}
UIColor *c = ([NetworkConnection sharedInstance].state == kIRCCloudStateConnected)?([UIColor isDarkTheme]?[UIColor whiteColor]:[UIColor unreadBlueColor]):[UIColor textareaBackgroundColor];
[self->_sendBtn setTitleColor:c forState:UIControlStateNormal];
[self->_sendBtn setTitleColor:c forState:UIControlStateDisabled];
[self->_sendBtn setTitleColor:c forState:UIControlStateHighlighted];

if(self->_handoffTimer)
[self->_handoffTimer invalidate];
self->_handoffTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(_updateHandoffTimer) userInfo:nil repeats:NO];
}

-(void)_cancelHandoffTimer {
if(self->_handoffTimer)
[self->_handoffTimer invalidate];
_handoffTimer = nil;
}

-(void)_updateHandoffTimer {
_handoffTimer = nil;
[[self userActivity] setNeedsSave:YES];
[self userActivityWillSave:[self userActivity]];
if(self->_buffer) {
self->_buffer.draft = _message.text.length ? _message.text : nil;
}
}

-(BOOL)expandingTextViewShouldReturn:(UIExpandingTextView *)expandingTextView {
Expand Down Expand Up @@ -2843,6 +2857,7 @@ -(void)launchURL:(NSURL *)url {

-(void)bufferSelected:(int)bid {
[self performSelectorOnMainThread:@selector(cancelSuggestionsTimer) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(_cancelHandoffTimer) withObject:nil waitUntilDone:NO];
_sortedChannels = nil;
_sortedUsers = nil;
BOOL changed = (self->_buffer && _buffer.bid != bid) || !_buffer;
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168
169

0 comments on commit 1d1390b

Please sign in to comment.