Skip to content
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

Autocomplete add button functionality & ui tweaks #24

Merged
merged 1 commit into from Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions Core/PartiallyRoundedRectangleView.swift
@@ -0,0 +1,45 @@
//
// PartiallyRoundedRectangleView.swift
// DuckDuckGo
//
// Created by Mia Alexiou on 15/03/2017.
// Copyright © 2017 DuckDuckGo. All rights reserved.
//

import UIKit

@IBDesignable
public class PartiallyRoundedRectangleView: UIView {

@IBInspectable var borderColor: UIColor = UIColor.white {
didSet {
layer.borderColor = borderColor.cgColor
}
}

@IBInspectable var borderWidth: CGFloat = 2.0 {
didSet {
layer.borderWidth = borderWidth
}
}

@IBInspectable var cornerRadius: CGFloat = 0.0

@IBInspectable var topLeftCorner: Bool = true

@IBInspectable var topRightCorner: Bool = true

@IBInspectable var bottomLeftCorner: Bool = true

@IBInspectable var bottomRightCorner: Bool = true

override public func layoutSubviews() {
super.layoutSubviews()
var corners = UIRectCorner()
if topLeftCorner { corners.insert(.topLeft) }
if topRightCorner { corners.insert(.topRight) }
if bottomLeftCorner { corners.insert(.bottomLeft) }
if bottomRightCorner { corners.insert(.bottomRight) }
round(corners: corners, radius: cornerRadius)
}
}
7 changes: 7 additions & 0 deletions Core/UIViewExtension.swift
Expand Up @@ -30,4 +30,11 @@ extension UIView {
attribute: .width, multiplier: 1, constant: 0))
}

public func round(corners: UIRectCorner, radius: CGFloat) {
let cornerRadii = CGSize(width: radius, height: radius)
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: cornerRadii)
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
layer.mask = maskLayer
}
}
10 changes: 7 additions & 3 deletions DuckDuckGo.xcodeproj/project.pbxproj
Expand Up @@ -51,6 +51,7 @@
F1617C151E57336D00DEDCAF /* TabManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1617C141E57336D00DEDCAF /* TabManager.swift */; };
F1617C191E573EA800DEDCAF /* TabSwitcherDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1617C181E573EA800DEDCAF /* TabSwitcherDelegate.swift */; };
F16390821E648B7A005B4550 /* HomeTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16390811E648B7A005B4550 /* HomeTabViewController.swift */; };
F1668BCB1E796366008CBA04 /* PartiallyRoundedRectangleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1668BCA1E796366008CBA04 /* PartiallyRoundedRectangleView.swift */; };
F176699A1E3FA5EE003D3222 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17669991E3FA5EE003D3222 /* Version.swift */; };
F176699F1E40BC86003D3222 /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F176699D1E40BC86003D3222 /* Settings.storyboard */; };
F17669A31E411DB8003D3222 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17669991E3FA5EE003D3222 /* Version.swift */; };
Expand Down Expand Up @@ -201,6 +202,7 @@
F1617C141E57336D00DEDCAF /* TabManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabManager.swift; sourceTree = "<group>"; };
F1617C181E573EA800DEDCAF /* TabSwitcherDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabSwitcherDelegate.swift; sourceTree = "<group>"; };
F16390811E648B7A005B4550 /* HomeTabViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeTabViewController.swift; sourceTree = "<group>"; };
F1668BCA1E796366008CBA04 /* PartiallyRoundedRectangleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PartiallyRoundedRectangleView.swift; sourceTree = "<group>"; };
F17669991E3FA5EE003D3222 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
F176699E1E40BC86003D3222 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Settings.storyboard; sourceTree = "<group>"; };
F17669A71E412A12003D3222 /* MockBundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockBundle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -324,7 +326,7 @@
F1BE54481E69DD5F00FCF649 /* Onboarding */,
F1C5ECFA1E37B15B00C599A4 /* Main */,
F16390801E648B68005B4550 /* Tabs */,
F1386BA21E6846320062FC3C /* TabSelector */,
F1386BA21E6846320062FC3C /* TabSwitcher */,
F1C4A70C1E5771F800A6CA1B /* OmniBar */,
F15D43211E70849A00BF2CDC /* Autocomplete */,
F1AB2B401E3F75A000868554 /* Settings */,
Expand Down Expand Up @@ -357,14 +359,14 @@
name = UserInterfaceResources;
sourceTree = "<group>";
};
F1386BA21E6846320062FC3C /* TabSelector */ = {
F1386BA21E6846320062FC3C /* TabSwitcher */ = {
isa = PBXGroup;
children = (
F1617C181E573EA800DEDCAF /* TabSwitcherDelegate.swift */,
F1617C121E572E0300DEDCAF /* TabSwitcherViewController.swift */,
F1DE78571E5CAE350058895A /* TabViewCell.swift */,
);
name = TabSelector;
name = TabSwitcher;
sourceTree = "<group>";
};
F143C2E51E4A4CD400CFDE3A /* Core */ = {
Expand Down Expand Up @@ -406,6 +408,7 @@
children = (
F143C3411E4A9C9A00CFDE3A /* UserText.swift */,
F143C32B1E4A9A4800CFDE3A /* RoundedRectangleView.swift */,
F1668BCA1E796366008CBA04 /* PartiallyRoundedRectangleView.swift */,
F143C3451E4AA32D00CFDE3A /* SearchBarExtension.swift */,
F143C32C1E4A9A4800CFDE3A /* UIViewControllerExtension.swift */,
F1B745211E549D550072547E /* UIColorExtension.swift */,
Expand Down Expand Up @@ -931,6 +934,7 @@
F143C3291E4A9A0E00CFDE3A /* URLExtension.swift in Sources */,
F143C3271E4A9A0E00CFDE3A /* Logger.swift in Sources */,
F143C32F1E4A9A4800CFDE3A /* UIViewControllerExtension.swift in Sources */,
F1668BCB1E796366008CBA04 /* PartiallyRoundedRectangleView.swift in Sources */,
F143C32E1E4A9A4800CFDE3A /* RoundedRectangleView.swift in Sources */,
F1DE785A1E5CD2A70058895A /* UIViewExtension.swift in Sources */,
F143C3261E4A9A0E00CFDE3A /* GroupData.swift in Sources */,
Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/AutocompleteViewController.swift
Expand Up @@ -11,6 +11,8 @@ import Core

class AutocompleteViewController: UIViewController {

@IBOutlet weak var widthConstraint: NSLayoutConstraint!

var delegate: AutocompleteViewControllerDelegate?

private lazy var parser = AutocompleteParser()
Expand Down Expand Up @@ -59,6 +61,11 @@ class AutocompleteViewController: UIViewController {
requestSuggestions(query: query)
}

@IBAction func onPlusButtonPressed(_ button: UIButton) {
let suggestion = suggestions[button.tag]
delegate?.autocomplete(pressedPlusButtonForSuggestion: suggestion.suggestion)
}

private func cancelInFlightRequests() {
if let inFlightRequest = lastRequest {
inFlightRequest.cancel()
Expand Down Expand Up @@ -95,6 +102,7 @@ extension AutocompleteViewController: UITableViewDataSource {
let type = SuggestionTableViewCell.reuseIdentifier
let cell = tableView.dequeueReusableCell(withIdentifier: type, for: indexPath) as! SuggestionTableViewCell
cell.updateFor(query: query, suggestion: suggestions[indexPath.row])
cell.plusButton.tag = indexPath.row
return cell
}

Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/AutocompleteViewControllerDelegate.swift
Expand Up @@ -12,4 +12,6 @@ import Foundation
protocol AutocompleteViewControllerDelegate {

func autocomplete(selectedSuggestion suggestion: String)

func autocomplete(pressedPlusButtonForSuggestion suggestion: String)
}
43 changes: 26 additions & 17 deletions DuckDuckGo/Base.lproj/Autocomplete.storyboard
Expand Up @@ -21,7 +21,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="EAI-u8-HTS" customClass="RoundedRectangleView" customModule="Core">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="EAI-u8-HTS" customClass="PartiallyRoundedRectangleView" customModule="Core">
<rect key="frame" x="14" y="22" width="347" height="278"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" scrollEnabled="NO" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="46" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="NI7-km-NQP">
Expand All @@ -42,34 +42,38 @@
<constraint firstAttribute="width" constant="18" id="eRs-db-3SW"/>
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Plus" translatesAutoresizingMaskIntoConstraints="NO" id="bqR-1T-AF7">
<rect key="frame" x="313" y="14" width="18" height="18"/>
<color key="tintColor" red="0.7019608021" green="0.7019608021" blue="0.7019608021" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="U9t-KT-S28"/>
<constraint firstAttribute="width" constant="18" id="nSh-Ih-0qq"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qWx-AW-1JS">
<rect key="frame" x="42" y="13" width="259" height="18"/>
<rect key="frame" x="42" y="13" width="251" height="18"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="15"/>
<color key="textColor" red="0.49803921579999999" green="0.49803921579999999" blue="0.49803921579999999" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2Vt-0M-Hjg">
<rect key="frame" x="305" y="8" width="30" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="JSK-3e-Inr"/>
<constraint firstAttribute="width" constant="30" id="SFn-9o-0Ax"/>
</constraints>
<color key="tintColor" red="0.49803921579999999" green="0.49803921579999999" blue="0.49803921579999999" alpha="1" colorSpace="calibratedRGB"/>
<state key="normal" image="Plus"/>
<connections>
<action selector="onPlusButtonPressed:" destination="WBd-4H-sHO" eventType="touchUpInside" id="8XV-nC-zOt"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="2Vt-0M-Hjg" secondAttribute="trailing" constant="8" id="023-2a-aHJ"/>
<constraint firstItem="2Vt-0M-Hjg" firstAttribute="leading" secondItem="qWx-AW-1JS" secondAttribute="trailing" constant="12" id="25t-ML-zyK"/>
<constraint firstItem="ESE-Rj-Bim" firstAttribute="leading" secondItem="xqJ-kD-Lnu" secondAttribute="leadingMargin" constant="4" id="80f-20-WI9"/>
<constraint firstItem="bqR-1T-AF7" firstAttribute="centerY" secondItem="xqJ-kD-Lnu" secondAttribute="centerY" id="92A-BF-Sk3"/>
<constraint firstItem="2Vt-0M-Hjg" firstAttribute="centerY" secondItem="xqJ-kD-Lnu" secondAttribute="centerY" id="P2B-JV-zyR"/>
<constraint firstItem="qWx-AW-1JS" firstAttribute="leading" secondItem="ESE-Rj-Bim" secondAttribute="trailing" constant="12" id="mKU-Mb-emI"/>
<constraint firstItem="bqR-1T-AF7" firstAttribute="leading" secondItem="qWx-AW-1JS" secondAttribute="trailing" constant="12" id="q8T-yI-bLF"/>
<constraint firstItem="qWx-AW-1JS" firstAttribute="centerY" secondItem="xqJ-kD-Lnu" secondAttribute="centerY" id="qVn-38-VVp"/>
<constraint firstItem="ESE-Rj-Bim" firstAttribute="centerY" secondItem="xqJ-kD-Lnu" secondAttribute="centerY" id="rqR-nE-gpD"/>
<constraint firstAttribute="trailingMargin" secondItem="bqR-1T-AF7" secondAttribute="trailing" constant="4" id="x2U-WD-nZX"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="label" destination="qWx-AW-1JS" id="MbC-jn-O3m"/>
<outlet property="plusImage" destination="bqR-1T-AF7" id="88Z-5V-Ugw"/>
<outlet property="plusButton" destination="2Vt-0M-Hjg" id="osX-6f-fQ6"/>
<outlet property="typeImage" destination="ESE-Rj-Bim" id="IeZ-bG-MMr"/>
</connections>
</tableViewCell>
Expand Down Expand Up @@ -105,6 +109,7 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="NI7-km-NQP" secondAttribute="bottom" constant="2" id="UpP-O9-rk2"/>
<constraint firstAttribute="width" constant="347" id="YZw-yg-XAd"/>
<constraint firstAttribute="trailing" secondItem="NI7-km-NQP" secondAttribute="trailing" constant="2" id="auX-AA-cEv"/>
<constraint firstItem="NI7-km-NQP" firstAttribute="top" secondItem="EAI-u8-HTS" secondAttribute="top" constant="2" id="cAX-Xx-6HJ"/>
<constraint firstItem="NI7-km-NQP" firstAttribute="leading" secondItem="EAI-u8-HTS" secondAttribute="leading" constant="2" id="iTF-f3-mZs"/>
Expand All @@ -120,23 +125,27 @@
<userDefinedRuntimeAttribute type="color" keyPath="borderColor">
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="topLeftCorner" value="NO"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="topRightCorner" value="NO"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="bottomLeftCorner" value="YES"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="bottomRightCorner" value="YES"/>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.20000000000000001" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="EAI-u8-HTS" firstAttribute="top" secondItem="LXz-1w-VYJ" secondAttribute="bottom" constant="2" id="myR-iT-hAK"/>
<constraint firstItem="EAI-u8-HTS" firstAttribute="leading" secondItem="Emd-u2-dVY" secondAttribute="leading" constant="14" id="reR-DT-SCa"/>
<constraint firstAttribute="trailing" secondItem="EAI-u8-HTS" secondAttribute="trailing" constant="14" id="snR-70-oxp"/>
<constraint firstItem="EAI-u8-HTS" firstAttribute="centerX" secondItem="Emd-u2-dVY" secondAttribute="centerX" id="xqD-gc-Lz4"/>
</constraints>
</view>
<connections>
<outlet property="tableView" destination="NI7-km-NQP" id="dy2-JZ-sMs"/>
<outlet property="widthConstraint" destination="YZw-yg-XAd" id="Okf-AJ-lUH"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="wo5-Nh-Wrd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1846.5" y="10.5"/>
<point key="canvasLocation" x="1845.5999999999999" y="10.344827586206897"/>
</scene>
</scenes>
<resources>
Expand Down