Skip to content

Commit

Permalink
Merge pull request #68 from sergstav/master
Browse files Browse the repository at this point in the history
HakawaiSwiftDemo
  • Loading branch information
jmkk authored May 18, 2018
2 parents 52be6a1 + 718fa33 commit 5552ae4
Show file tree
Hide file tree
Showing 17 changed files with 1,116 additions and 0 deletions.
Binary file added HakawaiDemoSwift/.DS_Store
Binary file not shown.
450 changes: 450 additions & 0 deletions HakawaiDemoSwift/HakawaiDemoSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
50 changes: 50 additions & 0 deletions HakawaiDemoSwift/HakawaiDemoSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AppDelegate.swift
// HakawaiDemoSwift
//
// Copyright (c) 2014 LinkedIn Corp. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

69 changes: 69 additions & 0 deletions HakawaiDemoSwift/HakawaiDemoSwift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Mentions Demo View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="MentionsDemoViewController" customModule="HakawaiDemoSwift" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="aaM-he-1fg" customClass="HKWTextView">
<rect key="frame" x="20" y="26" width="335" height="220"/>
<color key="backgroundColor" red="0.602715373" green="0.9820959534" blue="0.602715373" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="220" id="i7M-ua-mb8"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VNu-o4-Tz7">
<rect key="frame" x="20" y="263" width="92" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="chA-Ds-un3"/>
</constraints>
<state key="normal" title="List Mentions"/>
<connections>
<action selector="listMentionsButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="7Kn-LG-82m"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="B8a-CQ-yfy">
<rect key="frame" x="267" y="263" width="88" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Done editing"/>
<connections>
<action selector="doneEditingButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="COT-Ho-KCb"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="aaM-he-1fg" secondAttribute="trailing" constant="20" id="1F1-ss-1cp"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="VNu-o4-Tz7" secondAttribute="trailing" constant="20" symbolic="YES" id="dGt-y1-JBR"/>
<constraint firstItem="VNu-o4-Tz7" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="g5d-Ok-0jU"/>
<constraint firstItem="aaM-he-1fg" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="6" id="iNv-pw-F3d"/>
<constraint firstItem="aaM-he-1fg" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="jy0-qx-i1S"/>
<constraint firstItem="VNu-o4-Tz7" firstAttribute="top" secondItem="aaM-he-1fg" secondAttribute="bottom" constant="17" id="riJ-aE-Jjy"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="textView" destination="aaM-he-1fg" id="hmx-kA-yy6"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="140" y="133.5832083958021"/>
</scene>
</scenes>
</document>
87 changes: 87 additions & 0 deletions HakawaiDemoSwift/HakawaiDemoSwift/Mentions/CustomChooserView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// CustomChooserView.swift
// HakawaiDemoSwift
//
// Copyright (c) 2014 LinkedIn Corp. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//

import UIKit
import Hakawai

class CustomChooserView: UIView {

@IBOutlet weak var pickerView: UIPickerView!

weak var delegate: HKWCustomChooserViewDelegate?
var borderMode: HKWChooserBorderMode = .top

// Protocol factory method
@objc(chooserViewWithFrame:delegate:)
class func chooserView(withFrame frame: CGRect, delegate: HKWCustomChooserViewDelegate) -> Any {
let item = Bundle.main.loadNibNamed("CustomChooserView", owner: nil, options: nil)?[0] as! CustomChooserView
item.delegate = delegate
item.frame = frame
item.setNeedsLayout()
return item
}

override func awakeFromNib() {
super.awakeFromNib()
pickerView.dataSource = self
pickerView.delegate = self
}
}

// MARK: - HKWChooserViewProtocol
extension CustomChooserView: HKWChooserViewProtocol {
func becomeVisible() {
isHidden = false
setNeedsLayout()
}

func resetScrollPositionAndHide() {
// Don't do anything
isHidden = true
}

func reloadData() {
pickerView.reloadComponent(0)
}


}

// MARK: - UIPickerViewDataSource
extension CustomChooserView: UIPickerViewDataSource {

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return delegate?.numberOfModelObjects() ?? 0
}
}

//MARK: - UIPickerViewDelegate
extension CustomChooserView: UIPickerViewDelegate {

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let model = delegate?.modelObject(for: row) as! HKWMentionsEntityProtocol
return model.entityName()
}
}

// MARK: - Controls
extension CustomChooserView {

@IBAction func chooseButtonTapped(_ sender: UIButton) {
let idx = pickerView.selectedRow(inComponent: 0)
delegate?.modelObjectSelected(at: idx)
}
}
59 changes: 59 additions & 0 deletions HakawaiDemoSwift/HakawaiDemoSwift/Mentions/CustomChooserView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="CustomChooserView" customModule="HakawaiDemoSwift" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="370" height="252"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rv2-92-Mts">
<rect key="frame" x="159" y="206" width="53" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="VxM-bV-gRe"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="Choose">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="chooseButtonTapped:" destination="iN0-l3-epB" eventType="touchUpInside" id="AL4-iu-4mU"/>
</connections>
</button>
<pickerView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8bi-GX-QyU">
<rect key="frame" x="65" y="6" width="240" height="162"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="Lm6-NF-ayK"/>
</constraints>
</pickerView>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<constraints>
<constraint firstItem="8bi-GX-QyU" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="iN0-l3-epB" secondAttribute="leading" constant="12" id="4AN-bO-40J"/>
<constraint firstItem="rv2-92-Mts" firstAttribute="top" relation="greaterThanOrEqual" secondItem="8bi-GX-QyU" secondAttribute="bottom" constant="8" id="6ca-U0-YCU"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="8bi-GX-QyU" secondAttribute="trailing" constant="12" id="9kg-YW-kOv"/>
<constraint firstAttribute="centerX" secondItem="8bi-GX-QyU" secondAttribute="centerX" id="SOh-wx-jQ4"/>
<constraint firstAttribute="centerX" secondItem="rv2-92-Mts" secondAttribute="centerX" id="nRe-Sl-1f6"/>
<constraint firstAttribute="bottom" secondItem="rv2-92-Mts" secondAttribute="bottom" constant="16" id="wvo-DB-ScI"/>
<constraint firstItem="8bi-GX-QyU" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="6" id="yss-Gj-cqd"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="pickerView" destination="8bi-GX-QyU" id="YVP-DF-Pgd"/>
</connections>
<point key="canvasLocation" x="972" y="666"/>
</view>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// MentionsDemoViewController.swift
// HakawaiDemoSwift
//
// Copyright (c) 2014 LinkedIn Corp. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//

import UIKit
import Hakawai

class MentionsDemoViewController: UIViewController {

//MARK: - Outlets
@IBOutlet weak var textView: HKWTextView!
@IBOutlet weak var mentionsListButton: UIButton!

private var plugin: HKWMentionsPlugin?

override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
}

// MARK: -
extension MentionsDemoViewController {

private func setupUI() {
textView.layer.borderWidth = 0.5
textView.layer.borderColor = UIColor.lightGray.cgColor
// Set up the mentions system
let mode = HKWMentionsChooserPositionMode.enclosedTop
// In this demo, the user may explicitly begin a mention with either the '@' or '+' characters
let controlCharacters = CharacterSet(charactersIn: "@+")
// The user may also begin a mention by typing three characters (set searchLength to 0 to disable)
let mentionsPlugin = HKWMentionsPlugin(chooserMode: mode,
controlCharacters: controlCharacters,
searchLength: 3)

// NOTE: If you want to see an example of a custom chooser, uncomment the following line.
// mentionsPlugin?.chooserViewClass = CustomChooserView.self

// If the text view loses focus while the mention chooser is up, and then regains focus, it will automatically put
// the mentions chooser back up
mentionsPlugin?.resumeMentionsCreationEnabled = true
// Add edge insets so chooser view doesn't overlap the text view's cosmetic grey border
mentionsPlugin?.chooserViewEdgeInsets = UIEdgeInsetsMake(2, 0.5, 0.5, 0.5)
plugin = mentionsPlugin
plugin?.chooserViewBackgroundColor = .lightGray
// The mentions plug-in requires a delegate, which provides it with mentions entities in response to a query string
mentionsPlugin?.delegate = MentionsManager.shared
textView.controlFlowPlugin = mentionsPlugin
}
}

// MARK: - Controls
extension MentionsDemoViewController {

@IBAction func listMentionsButtonTapped(_ sender: UIButton) {
print("There are mention(s): \(String(describing: plugin?.mentions().count)) @% \(String(describing: plugin?.mentions()))")
}

@IBAction func doneEditingButtonTapped(_ sender: UIButton) {
textView.resignFirstResponder()
}
}
Loading

0 comments on commit 5552ae4

Please sign in to comment.