-
Notifications
You must be signed in to change notification settings - Fork 34
Tooltips #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Tooltips #218
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b46482
Added tooltips implementation
Ostrenkiy 8c34d0d
added subscription handling for tooltips in SectionsViewController
Ostrenkiy 8aaeb2a
Added tooltip for download on lessons
Ostrenkiy c72b6f6
Added continue learning widget tooltip
Ostrenkiy f5e697b
Added tooltip for streaks & fixes to continue learning widget tooltip
Ostrenkiy ef19102
Tooltip color changes
Ostrenkiy 5d25448
Added localization to tooltips
Ostrenkiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // | ||
| // Tooltip.swift | ||
| // Stepic | ||
| // | ||
| // Created by Ostrenkiy on 19.01.2018. | ||
| // Copyright © 2018 Alex Karpov. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
| import EasyTipView | ||
|
|
||
| protocol Tooltip { | ||
| init(text: String, shouldDismissAfterTime: Bool, color: TooltipColor) | ||
| func show(direction: TooltipDirection, in inView: UIView?, from fromView: UIView) | ||
| func show(direction: TooltipDirection, in inView: UIView?, from fromItem: UIBarButtonItem) | ||
| func dismiss() | ||
| } | ||
|
|
||
| enum TooltipColor { | ||
| case light, dark, standard | ||
|
|
||
| var textColor: UIColor { | ||
| switch self { | ||
| case .light: | ||
| return UIColor.mainDark | ||
| case .dark: | ||
| return UIColor.mainLight | ||
| case .standard: | ||
| return UIColor.white | ||
| } | ||
| } | ||
|
|
||
| var borderColor: UIColor { | ||
| switch self { | ||
| case .light: | ||
| return UIColor.mainDark | ||
| case .dark: | ||
| return UIColor.mainLight | ||
| case .standard: | ||
| return UIColor.thirdColor | ||
| } | ||
| } | ||
|
|
||
| var backgroundColor: UIColor { | ||
| switch self { | ||
| case .light: | ||
| return UIColor.mainLight | ||
| case .dark: | ||
| return UIColor.mainDark | ||
| case .standard: | ||
| return UIColor.thirdColor | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class EasyTipTooltip: Tooltip { | ||
| private var easyTip: EasyTipView = EasyTipView(text: "") | ||
| private var preferences: EasyTipView.Preferences | ||
| let dismissesAfter: TimeInterval = 7.5 | ||
|
|
||
| var text: String | ||
| var shouldDismissAfterTime: Bool | ||
|
|
||
| private func easyTipDirectionFromTooltipDirection(direction: TooltipDirection) -> EasyTipView.ArrowPosition { | ||
| switch direction { | ||
| case .up: | ||
| return EasyTipView.ArrowPosition.top | ||
| case .left: | ||
| return EasyTipView.ArrowPosition.left | ||
| case .right: | ||
| return EasyTipView.ArrowPosition.right | ||
| case .down: | ||
| return EasyTipView.ArrowPosition.bottom | ||
| } | ||
| } | ||
|
|
||
| required init(text: String, shouldDismissAfterTime: Bool, color: TooltipColor) { | ||
| self.text = text | ||
| self.shouldDismissAfterTime = shouldDismissAfterTime | ||
| preferences = EasyTipView.Preferences() | ||
| preferences.drawing.font = UIFont.systemFont(ofSize: 14) | ||
| preferences.drawing.foregroundColor = color.textColor | ||
| preferences.drawing.backgroundColor = color.backgroundColor | ||
| preferences.drawing.borderWidth = 1.0 | ||
| preferences.drawing.borderColor = color.borderColor | ||
| } | ||
|
|
||
| private func setupTooltip(direction: TooltipDirection) { | ||
| preferences.drawing.arrowPosition = easyTipDirectionFromTooltipDirection(direction: direction) | ||
| easyTip = EasyTipView(text: text, preferences: preferences, delegate: nil) | ||
| } | ||
|
|
||
| private func setupDisappear() { | ||
| guard shouldDismissAfterTime else { | ||
| return | ||
| } | ||
| delay(dismissesAfter) { | ||
| [weak self] in | ||
| self?.dismiss() | ||
| } | ||
| } | ||
|
|
||
| func show(direction: TooltipDirection, in inView: UIView?, from fromView: UIView) { | ||
| setupTooltip(direction: direction) | ||
| easyTip.show(forView: fromView, withinSuperview: inView) | ||
| setupDisappear() | ||
| } | ||
|
|
||
| func show(direction: TooltipDirection, in inView: UIView?, from fromItem: UIBarButtonItem) { | ||
| setupTooltip(direction: direction) | ||
| easyTip.show(forItem: fromItem, withinSuperView: inView) | ||
| setupDisappear() | ||
| } | ||
|
|
||
| func dismiss() { | ||
| easyTip.dismiss() | ||
| } | ||
| } | ||
|
|
||
| enum TooltipDirection { | ||
| case left, up, right, down | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему какой-то форк юзаем? Swift 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да