Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bmoliveira committed Jul 19, 2016
1 parent e72f648 commit 0a48022
Show file tree
Hide file tree
Showing 78 changed files with 4,883 additions and 63 deletions.
27 changes: 7 additions & 20 deletions BOShareComposer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,21 @@
Pod::Spec.new do |s|
s.name = 'BOShareComposer'
s.version = '0.1.0'
s.summary = 'A short description of BOShareComposer.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.summary = 'A simple text + URL share composer'
s.description = <<-DESC
TODO: Add long description of the pod here.
Composer like share to do custom shares, example: share via direct message twitter they dont have
any composer to send direct messages
DESC

s.homepage = 'https://github.com/<GITHUB_USERNAME>/BOShareComposer'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.homepage = 'https://github.com/bmoliveira/BOShareComposer'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Bruno Oliveira' => '[email protected]' }
s.source = { :git => 'https://github.com/<GITHUB_USERNAME>/BOShareComposer.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.source = { :git => 'https://github.com/bmoliveira/BOShareComposer.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/_bmoliveira>'

s.ios.deployment_target = '8.0'

s.source_files = 'BOShareComposer/Classes/**/*'

# s.resource_bundles = {
# 'BOShareComposer' => ['BOShareComposer/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.dependency 'SnapKit', '= 0.30.0.beta2'
end
Empty file.
15 changes: 15 additions & 0 deletions BOShareComposer/Classes/ShareDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BOShareDelegate.swift
// Pods
//
// Created by Bruno Oliveira on 19/07/16.
//
//

import Foundation

public protocol ShareDelegate {
func willAppear()
func submit(viewModel: ShareViewModel)
func willDisapear()
}
208 changes: 208 additions & 0 deletions BOShareComposer/Classes/ShareViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
//
// ShareViewController.swift
// BOShareComposer
//
// Created by Bruno Oliveira on 19/07/16.
// Copyright © 2016 CocoaPods. All rights reserved.
//

import UIKit
import SnapKit

public extension BOShareViewController {
public static func presentShareViewController(from viewController: UIViewController,
shareViewModel: ShareViewModel,
shareDelegate: ShareDelegate,
completion: (()->())? = nil) {

viewController.navigationController?.modalPresentationStyle = .OverCurrentContext
viewController.modalPresentationStyle = .OverCurrentContext
let shareViewController = BOShareViewController()
shareViewController.shareDelegate = shareDelegate
shareViewController.viewModel = shareViewModel

viewController.presentViewController(shareViewController,
animated: false,
completion: completion)
}
}

public class BOShareViewController: UIViewController {

var viewModel: ShareViewModel?
var shareDelegate: ShareDelegate?

lazy var cancelButton: UIButton = {
let button = UIButton(type: UIButtonType.System)
button.setTitle("Cancel", forState: .Normal)
button.addTarget(self, action: #selector(cancelAction), forControlEvents: .TouchUpInside)
return button
}()

lazy var confirmButton: UIButton = {
let button = UIButton(type: UIButtonType.System)
button.setTitle("Send", forState: .Normal)
button.addTarget(self, action: #selector(sendAction), forControlEvents: .TouchUpInside)
return button
}()

lazy var popupTitle: UILabel = {
let label = UILabel()
label.text = "Share"
return label
}()

lazy var titleDivider: UIView = {
let view = UIView()
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
return view
}()

lazy var popupBody: UITextView = {
let textField = UITextView()
textField.editable = true
textField.backgroundColor = UIColor.clearColor()
textField.scrollEnabled = true
textField.text = "A random message to send to a dummy user!"
textField.font = UIFont.systemFontOfSize(18)
textField.becomeFirstResponder()
return textField
}()

lazy var backgroundView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7)
return view
}()

lazy var containerView: UIVisualEffectView = {
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight))
visualEffectView.layer.cornerRadius = 8
visualEffectView.clipsToBounds = true
visualEffectView.alpha = 0
return visualEffectView
}()

override public func viewDidLoad() {
super.viewDidLoad()
setupViews()
}

public override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
shareDelegate?.willAppear()
popupTitle.text = viewModel?.title ?? ""
popupBody.text = viewModel?.text ?? ""
showView()
}

public override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
shareDelegate?.willDisapear()
hideView()
}

func cancelAction() {
hideView { _ in
self.dismissViewControllerAnimated(false, completion: nil)
}
}

func sendAction() {
if var viewModel = viewModel {
viewModel.text = popupBody.text
shareDelegate?.submit(viewModel)
}
hideView { _ in
self.dismissViewControllerAnimated(false, completion: nil)
}
}
}



extension BOShareViewController {

private func showView() {
UIView.animateWithDuration(0.5) {
self.containerView.alpha = 1
}
}

private func hideView(completion: ((Bool)->())? = nil) {
popupBody.resignFirstResponder()
UIView.animateWithDuration(0.5) {
self.backgroundView.alpha = 0
}

UIView.animateWithDuration(0.5,
animations: {
self.containerView.alpha = 0
},
completion: completion)
}

private func setupViews() {
view.backgroundColor = UIColor.whiteColor()
view.addSubview(backgroundView)
backgroundView.snp_makeConstraints { make in
make.edges.equalTo(self.view)
}

view.addSubview(containerView)

containerView.snp.makeConstraints { make in
make.top.equalTo(backgroundView).inset(60)
make.left.equalTo(backgroundView).inset(16)
make.right.equalTo(backgroundView).inset(16)
}

let contentView = containerView.contentView
contentView.addSubview(cancelButton)
cancelButton.snp_makeConstraints { make in
make.top.equalTo(contentView).inset(4)
make.left.equalTo(contentView).inset(8)
}

contentView.addSubview(confirmButton)
confirmButton.snp.makeConstraints { make in
make.top.equalTo(contentView).inset(4)
make.right.equalTo(contentView).inset(8)
}

contentView.addSubview(titleDivider)
titleDivider.snp.makeConstraints { make in
make.top.equalTo(cancelButton.snp_bottom)
make.left.equalTo(contentView)
make.right.equalTo(contentView)
make.height.equalTo(1)
}

contentView.addSubview(popupTitle)
popupTitle.snp.makeConstraints { make in
make.top.equalTo(contentView)
make.bottom.equalTo(titleDivider.snp_top)
make.centerX.equalTo(contentView)
make.left.equalTo(cancelButton.snp_right).priorityLow()
make.right.equalTo(confirmButton.snp_left).priorityLow()
}

let dummyContentView = UIView()
contentView.addSubview(dummyContentView)
dummyContentView.snp.makeConstraints { make in
make.top.equalTo(titleDivider.snp_bottom)
make.left.equalTo(contentView).inset(8)
make.right.equalTo(contentView).inset(8)
make.bottom.equalTo(contentView).inset(8)
make.height.equalTo(140)
}

dummyContentView.addSubview(popupBody)
popupBody.snp.makeConstraints { make in
make.top.equalTo(dummyContentView)
make.left.equalTo(dummyContentView)
make.right.equalTo(dummyContentView)
make.bottom.equalTo(dummyContentView)
}
}
}
23 changes: 23 additions & 0 deletions BOShareComposer/Classes/ShareViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ShareViewModel.swift
// Pods
//
// Created by Bruno Oliveira on 19/07/16.
//
//

import Foundation

public struct ShareViewModel {
public var text: String
public let link: NSURL?
public let title: String
public let destinationUserId: String?

public init(text: String, title: String = "Share", link: NSURL? = nil, destinationUserId: String? = nil){
self.text = text
self.title = title
self.link = link
self.destinationUserId = destinationUserId
}
}
26 changes: 26 additions & 0 deletions BOShareComposer/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
27 changes: 27 additions & 0 deletions BOShareComposer/SnapKit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// SnapKit
//
// Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT double SnapKitVersionNumber;
FOUNDATION_EXPORT const unsigned char SnapKitVersionString[];
Loading

0 comments on commit 0a48022

Please sign in to comment.