Module: Turbo::VisitableView::Screenshots

Included in:
Turbo::VisitableView
Defined in:
lib/turbo/visitable_view/screenshots.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#screenshotViewObject (readonly)

Returns the value of attribute screenshotView.



13
14
15
# File 'lib/turbo/visitable_view/screenshots.rb', line 13

def screenshotView
  @screenshotView
end

Instance Method Details

#clearScreenshotObject



51
52
53
# File 'lib/turbo/visitable_view/screenshots.rb', line 51

def clearScreenshot
  screenshotView.removeFromSuperview if screenshotView
end

#hideScreenshotObject



46
47
48
49
# File 'lib/turbo/visitable_view/screenshots.rb', line 46

def hideScreenshot
  screenshotContainerView.removeFromSuperview
  showOrHideWebView
end

#isShowingScreenshotObject



15
16
17
# File 'lib/turbo/visitable_view/screenshots.rb', line 15

def isShowingScreenshot
  screenshotContainerView.superview != nil
end

#screenshotContainerViewObject



4
5
6
7
8
9
10
11
# File 'lib/turbo/visitable_view/screenshots.rb', line 4

def screenshotContainerView
  @screenshotContainerView ||= begin
    view = UIView.alloc.initWithFrame(CGRectZero)
    view.translatesAutoresizingMaskIntoConstraints = false
    view.backgroundColor = backgroundColor
    view
  end
end

#showScreenshotObject



38
39
40
41
42
43
44
# File 'lib/turbo/visitable_view/screenshots.rb', line 38

def showScreenshot
  if !isShowingScreenshot && !isRefreshing
    addSubview(screenshotContainerView)
    addFillConstraintsForSubview(screenshotContainerView)
    showOrHideWebView
  end
end

#updateScreenshotObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/turbo/visitable_view/screenshots.rb', line 19

def updateScreenshot
  return unless webView
  return if isShowingScreenshot
  screenshot = webView.snapshotViewAfterScreenUpdates(false)
  return unless screenshot

  screenshotView.removeFromSuperview if screenshotView
  screenshot.translatesAutoresizingMaskIntoConstraints = false
  screenshotContainerView.addSubview(screenshot)

  NSLayoutConstraint.activateConstraints([
    screenshot.centerXAnchor.constraintEqualToAnchor(screenshotContainerView.centerXAnchor),
    screenshot.topAnchor.constraintEqualToAnchor(screenshotContainerView.topAnchor),
    screenshot.widthAnchor.constraintEqualToConstant(screenshot.bounds.size.width),
    screenshot.heightAnchor.constraintEqualToConstant(screenshot.bounds.size.height)
  ])
  @screenshotView = screenshot
end