Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 30, 2018
1 parent 9cde280 commit 6d1413c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Blink/ControlPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.distribution = UIStackViewDistributionEqualSpacing;
_stackView.spacing = 14;
_stackView.spacing = 12;

_clipboardToolbar = [[RoundedToolbar alloc] initWithFrame:CGRectZero];

Expand Down
52 changes: 3 additions & 49 deletions Blink/SpaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ - (void)loadView
[_viewportsController didMoveToParentViewController:self];

_touchOverlay = [[TouchOverlay alloc] initWithFrame:self.view.bounds];
[_touchOverlay attachPageViewController:_viewportsController];

[self.view addSubview:_touchOverlay];
_touchOverlay.touchDelegate = self;
_touchOverlay.controlPanel.controlPanelDelegate = self;
[_touchOverlay attachPageViewController:_viewportsController];


[self registerForNotifications];
Expand Down Expand Up @@ -250,25 +251,6 @@ -(void)_appWillResignActive


#pragma mark Events
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer
//{
// if (gestureRecognizer == _twoFingersTap && otherGestureRecognizer == _twoFingersDrag) {
// return YES;
// }
// if (gestureRecognizer == _twoFingersTap && [otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
// return YES;
// }
// return NO;
//}
//
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
//{
// if (gestureRecognizer == _twoFingersDrag && ![otherGestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]]) {
// return YES;
// }
//
// return NO;
//}

// The Space will be responsible to accommodate the work environment for widgets, adjusting the size, making sure it doesn't overlap content,
// moving widgets or scrolling to them when necessary, etc...
Expand Down Expand Up @@ -311,30 +293,6 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)sender
}
}

- (void)_handleTwoFingersTap:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateRecognized) {
[self _createShellWithUserActivity: nil sessionStateKey: nil animated:YES completion:nil];
}
}

- (CGAffineTransform)_transformForTranslation:(CGPoint)translation {

CGFloat scale = 0.5;//MAX(MIN(1 - (-translation.y * 3/ height), 0.5), 0.3);

CGAffineTransform move = CGAffineTransformMakeScale(scale, scale);
return CGAffineTransformTranslate(move, translation.x, translation.y);
}

//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
//{
// if (gestureRecognizer == _twoFingersDrag) {
// return [_twoFingersDrag translationInView:self.view].y < 0;
// }
//
// return YES;
//}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
Expand Down Expand Up @@ -888,13 +846,9 @@ - (void)touchOverlay:(TouchOverlay *)overlay onTwoFingerTap:(UITapGestureRecogni

- (void)touchOverlay:(TouchOverlay *)overlay onPinch:(UIPinchGestureRecognizer *)recognizer
{
[self.currentTerm.termView scaleWith:recognizer];
[self.currentTerm scaleWithPich:recognizer];
}

- (void)touchOverlay:(TouchOverlay *)overlay onScrollY:(CGFloat) y
{
// self.view.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, MIN(-y, 0));
}

-(void)controlPanelOnPaste
{
Expand Down
1 change: 1 addition & 0 deletions Blink/TermController.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- (void)focus;
- (void)blur;
- (void)reload;
- (void)scaleWithPich:(UIPinchGestureRecognizer *)pinch;

- (void)attachInput:(TermInput *)termInput;

Expand Down
19 changes: 19 additions & 0 deletions Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @implementation TermController {
MCPSession *_session;
NSDictionary *_activityUserInfo;
BOOL _isReloading;
NSInteger _fontSizeBeforeScaling;
}

- (void)loadView
Expand Down Expand Up @@ -309,6 +310,24 @@ - (void)attachInput:(TermInput *)termInput
}
}

- (void)scaleWithPich:(UIPinchGestureRecognizer *)pinch
{
switch (pinch.state) {
case UIGestureRecognizerStateBegan:
case UIGestureRecognizerStateEnded:
_fontSizeBeforeScaling = _sessionParameters.fontSize;
break;
case UIGestureRecognizerStateChanged: {
NSInteger newSize = (NSInteger)round(_fontSizeBeforeScaling * pinch.scale);
if (newSize != _sessionParameters.fontSize) {
[_termView setFontSize:@(newSize)];
}
}
default:
break;
}
}



@end
4 changes: 1 addition & 3 deletions Blink/TermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@
- (void)reset;

- (void)blur;
- (void)focus;
- (void)focus;
- (void)cleanSelection;
- (void)increaseFontSize;
- (void)decreaseFontSize;
- (void)resetFontSize;

- (void)scaleWith:(UIPinchGestureRecognizer *)recognizer;

- (void)modifySideOfSelection;
- (void)modifySelectionInDirection:(NSString *)direction granularity:(NSString *)granularity;
@end
106 changes: 3 additions & 103 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ @interface TermView () <UIGestureRecognizerDelegate, WKScriptMessageHandler>

@implementation TermView {
WKWebView *_webView;

UITapGestureRecognizer *_tapGesture;
UIPinchGestureRecognizer *_pinchGesture;

NSTimer *_pinchSamplingTimer;
BOOL _focused;

BOOL _jsIsBusy;
Expand Down Expand Up @@ -112,14 +108,6 @@ - (id)initWithFrame:(CGRect)frame
- (void)didMoveToWindow
{
[super didMoveToWindow];

if (self.window.screen == [UIScreen mainScreen]) {
[self _addGestures];
}
}

- (BOOL)isDragging {
return _webView.scrollView.panGestureRecognizer.state == UIGestureRecognizerStateRecognized;
}

- (BOOL)canBecomeFirstResponder {
Expand All @@ -135,6 +123,7 @@ - (void)_addWebView
_webView = [[BKWebView alloc] initWithFrame:self.bounds configuration:configuration];

_webView.scrollView.delaysContentTouches = NO;
_webView.scrollView.canCancelContentTouches = NO;
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.panGestureRecognizer.enabled = NO;

Expand All @@ -146,27 +135,6 @@ - (void)_addWebView
[self addSubview:_webView];
}


- (void)_addGestures
{

if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_activeControl:)];
[_tapGesture setNumberOfTapsRequired:1];
_tapGesture.delegate = self;
[_webView addGestureRecognizer:_tapGesture];
}


if (!_pinchGesture) {
// _pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(_handlePinch:)];
// _pinchGesture.delegate = self;
// [_webView addGestureRecognizer:_pinchGesture];
//
// [_pinchGesture requireGestureRecognizerToFail: _tapGesture];
}
}

- (NSString *)title
{
return _webView.title;
Expand Down Expand Up @@ -315,7 +283,7 @@ - (void)userContentController:(WKUserContentController *)userContentController
- (void)_handleSelectionChange:(NSDictionary *)data
{
_selectedText = data[@"text"];
_hasSelection = _selectedText.length > 0;
_hasSelection = _selectedText.length > 0;

if (!_hasSelection) {
return;
Expand Down Expand Up @@ -345,36 +313,12 @@ - (void)modifySideOfSelection
{
[_webView evaluateJavaScript:term_modifySideSelection() completionHandler:nil];
}

- (void)modifySelectionInDirection:(NSString *)direction granularity:(NSString *)granularity
{
[_webView evaluateJavaScript:term_modifySelection(direction, granularity) completionHandler:nil];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == _tapGesture) {
return YES;
}

return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == _pinchGesture && [otherGestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]]) {
return YES;
}
return NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer == _tapGesture) {
return !_hasSelection;
}
return YES;
}

- (NSURL *)_detectLinkInSelection:(NSDictionary *)data
{
__block NSURL *result = nil;
Expand Down Expand Up @@ -417,50 +361,6 @@ - (void)yank:(id)sender
{
}

- (void)_activeControl:(UITapGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateRecognized) {
return;
}

[_termDelegate focus];
}

- (void)_handlePinch:(UIPinchGestureRecognizer *)gestureRecognizer
{
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan:
[_pinchSamplingTimer invalidate];
_pinchSamplingTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(_pinchSampling:)
userInfo:nil repeats:YES];
break;
case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled:
[_pinchSamplingTimer invalidate];
break;
default:
break;
}
}

- (void)_pinchSampling:(NSTimer *)timer
{
[_webView evaluateJavaScript: term_scale(_pinchGesture.scale)
completionHandler:^(id _Nullable res, NSError * _Nullable error) {
_pinchGesture.scale = 1;
}];
}

- (void)scaleWith:(UIPinchGestureRecognizer *)recognizer
{
[_webView evaluateJavaScript: term_scale(recognizer.scale)
completionHandler:^(id _Nullable res, NSError * _Nullable error) {
recognizer.scale = 1;
}];
}

- (void)copy:(id)sender
{
[_webView copy:sender];
Expand Down
1 change: 0 additions & 1 deletion Blink/TouchOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- (void)touchOverlay:(TouchOverlay *)overlay onOneFingerTap:(UITapGestureRecognizer *)recognizer;
- (void)touchOverlay:(TouchOverlay *)overlay onTwoFingerTap:(UITapGestureRecognizer *)recognizer;
- (void)touchOverlay:(TouchOverlay *)overlay onPinch:(UIPinchGestureRecognizer *)recognizer;
- (void)touchOverlay:(TouchOverlay *)overlay onScrollY:(CGFloat) y;

@end

Expand Down
Loading

0 comments on commit 6d1413c

Please sign in to comment.