GithubHelp home page GithubHelp logo

yannickl / reactions Goto Github PK

View Code? Open in Web Editor NEW
584.0 18.0 90.0 393 KB

Fully customizable Facebook reactions like control

Home Page: http://cocoadocs.org/docsets/Reactions

License: MIT License

Swift 99.19% Ruby 0.81%
reactions facebook swift

reactions's Introduction

Reactions

Supported Platforms Version Swift Package Manager Carthage compatible Build status Code coverage status Codebeat badge

Reactions is a fully customizable control to give people more ways to share their reaction in a quick and easy way.

Reactions

RequirementsUsageInstallationContributionContactLicense

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.2+

Usage

Reaction

Reaction

A Reaction object is a model defined with these properties:

  • id: a unique identifier.
  • title: the title displayed either in a selector or a button.
  • color: the color used to display the button title.
  • icon: the reaction icon.
  • alternativeIcon: the optional alternative icon used with the reaction button.

The library already packages the standard Facebook reactions: like, love, haha, wow, sad and angry. And of course you can create your owns:

let myReaction = Reaction(id: "id", title: "title", color: .red, icon: UIImage(named: "name")!)

ReactionSelector

ReactionSelector

The ReactionSelector control allows people to select a reaction amongst a list:

let select       = ReactionSelector()
select.reactions = Reaction.facebook.all

// React to reaction change
select.addTarget(self, action: #selector(reactionDidChanged), for: .valueChanged)

func reactionDidChanged(_ sender: AnyObject) {
  print(select.selectedReaction)
}

// Conforming to the ReactionFeedbackDelegate
select.feedbackDelegate = self

func reactionFeedbackDidChanged(_ feedback: ReactionFeedback?) {
  // .slideFingerAcross, .releaseToCancel, .tapToSelectAReaction
}

The component can be used alone (like above) or in conjunction with the ReactionButton (discussed later). You can of course customize the component using a ReactionSelectorConfig object:

select.config = ReactionSelectorConfig {
  $0.spacing        = 6
  $0.iconSize       = 40
  $0.stickyReaction = false
}

ReactionButton

ReactionButton

A ReactionButton provides a simple way to toggle a reaction (e.g. like/unlike). A ReactionSelector can also be attached in order to display it when a long press is performed:

let button      = ReactionButton()
button.reaction = Reaction.facebook.like

// To attach a selector
button.reactionSelector = ReactionSelector()

You can configure the component using a ReactionButtonConfig object:

button.config         = ReactionButtonConfig() {
  $0.iconMarging      = 8
  $0.spacing          = 4
  $0.font             = UIFont(name: "HelveticaNeue", size: 14)
  $0.neutralTintColor = UIColor(red: 0.47, green: 0.47, blue: 0.47, alpha: 1)
  $0.alignment        = .left
}

ReactionSummary

ReactionSummary

The ReactionSummary is a control which display a given reaction list as a set of unique icons superimposed. You can also link it to a text description.

let summary       = ReactionSummary()
summary.reactions = Reaction.facebook.all
summary.text      = "You, Chris Lattner, and 16 others"

// As is a control you can also react to the .touchUpInside event
select.addTarget(self, action: #selector(summaryDidTouched), for: .touchUpInside)

ReactionSummary Non Aggregated

You can also have the details for each reaction. For that you'll need to uncombined them by setting the isAggregated config property to false.

summary.config = ReactionSummaryConfig {
  $0.isAggregated = false
}

Like the other components you can setting it using a ReactionSummaryConfig object:

summary.config = ReactionSummaryConfig {
  $0.spacing      = 8
  $0.iconMarging  = 2
  $0.font         = UIFont(name: "HelveticaNeue", size: 12)
  $0.textColor    = UIColor(red: 0.47, green: 0.47, blue: 0.47, alpha: 1)
  $0.alignment    = .left
  $0.isAggregated = true
}

Installation

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add Reactions:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

use_frameworks!
pod 'Reactions', '~> 3.0.0'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file):

$ open MyProject.xcworkspace

You can now import Reactions framework into your files.

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Reactions into your Xcode project using Carthage, specify it in your Cartfile file:

github "yannickl/Reactions" >= 3.0.0

Swift Package Manager

You can use The Swift Package Manager to install Reactions by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/yannickl/Reactions.git", versions: "3.0.0" ..< Version.max)
    ]
)

Note that the Swift Package Manager is still in early design and development, for more information checkout its GitHub Page.

Manually

Download the project and copy the Sources and Resources folders into your project to use it in.

Contribution

Contributions are welcomed and encouraged .

Contact

Yannick Loriot

License (MIT)

Copyright (c) 2016-present - Yannick Loriot

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.

reactions's People

Contributors

yannickl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactions's Issues

Reactions receives no input whatsoever.

I've added Reactions to a UIView and the animations do not change when I mouse hover or click, leading me to believe that it's receiving no input whatsoever. What could cause this?

var select = ReactionSelector()
select.reactions = Reaction.facebook.all
containerView.addSubview(select)

Fixing the `ReactionSummary` aggregate icons

For the moment the ReactionSummary icons are drawn with a white border. The white border is drawn inside the image so it crops it and thats not elegant. We should first draw a white circle and then the icon inside without border.

does not work after i call view from tabbar

when i go to the rection view from tabbar it give me error (Fatal error: Unexpectedly found nil while unwrapping an Optional value)
and some warnings like ([framework] CUICatalog: Invalid asset name supplied:

[1771:665213] Could not load the "" image referenced from a nib in the bundle with identifier " ")

feedback for feedback delegate

Could you explain how or what you can do with the feedback delegate because currently, it's just sitting in the swift file empty and the description doesn't really explain anything?

Overlay views are not getting removed from window

For each and every ReactionButton there will be an "overlay" view and that overlay view is attached to UIApplication window whenever user started to react.

But there is no where you are removing the "overlay" view from window, so because of this if user reacting on 100 cells will lead to create 100 overlay views and it wont get removed from superview even after user came out from that controller.

Steps To Reproduce:

1)Run the example Project
2)Press "View inside Tableview cells"
3)Do reactions in cells
4)Come out from the screen
5)Run the view inspector from your xcode,

You will get similar to this,

Screenshot 2020-02-27 at 4 59 58 PM

I reacted four times, so four overlays + reaction selector got created.

Solution:
We can remove the "overlay" view whenever ReactionButton removed from it's superview

How to set unselected reaction?

How to set unselected reaction once iboutlet did set?

i am using pod 'Reactions', '~> 1.1.1'

My first item selected reaction is a grey color. Just like its working on facebook reaction

@IBOutlet weak var reactionnButton: ReactionButton! {
        didSet {

            let select = ReactionSelector()
            let reactionLike =      Reaction(id: "id", title: "Like", color: .red, icon: #imageLiteral(resourceName: "like"))
            let reactionAngry =     Reaction(id: "id", title: "Angry", color: .red, icon: #imageLiteral(resourceName: "emoji_angry"))
            let reactionEnvy =      Reaction(id: "id", title: "Envy", color: .red, icon: #imageLiteral(resourceName: "emoji_envy"))
            let reactionLove =      Reaction(id: "id", title: "Love", color: .red, icon: #imageLiteral(resourceName: "emoji_love"))
            let reactionSick =      Reaction(id: "id", title: "Sick", color: .red, icon: #imageLiteral(resourceName: "emoji_sick"))
            let reactionHappy =     Reaction(id: "id", title: "Happy", color: .red, icon: #imageLiteral(resourceName: "emoji_happy"))
            let reactionCrying =    Reaction(id: "id", title: "Crying", color: .red, icon: #imageLiteral(resourceName: "emoji_crying"))
            
            select.reactions = [
                reactionLike,
                reactionAngry,
                reactionEnvy,
                reactionLove,
                reactionSick,
                reactionHappy,
                reactionCrying
            ]
            
            //select.reactions = Reaction.facebook.all
            
            //select.selectedReaction = Reaction(id: "id", title: "Angry", color: .red, icon: #imageLiteral(resourceName: "like-template"))
            
            reactionnButton.reactionSelector = select
            reactionnButton.config           = ReactionButtonConfig() {
                $0.iconMarging      = 15
                $0.spacing          = 5
                $0.font             = UIFont(name: "ApexRounded-Book", size: 14)
                $0.neutralTintColor = UIColor(red: 0.47, green: 0.47, blue: 0.47, alpha: 1)
                $0.alignment        = .centerLeft
            }
            
            
            
            reactionnButton.reactionSelector?.feedbackDelegate = self
            
            // This one takes a value from ReactionSelector
            reactionnButton.addTarget(self, action: #selector(reactionChanged), for: .valueChanged)
            // And this one from ReactionButton
            reactionnButton.addTarget(self, action: #selector(reactionChanged), for: .touchUpInside)
        }
    }

how i should integrate with objective c

I have tried so many types to assign the reaction values in objective c , bridging the file and so on, can you please tell how to integrate into objective c finally we triggered only define the class for that uiview and getting outlet of that uiview (ReactionSummary, ReactionSelector, ReactionButton)
and we can not able to delegate the method of "ReactionFeedbackDelegate" ,,,

Please tell if you done this...!! and explain it..

Thank you! !!!!!

I am not able to set custom icon.

Below is the code to set my custom icon. But still, it is showing library provided icon icon.

var reactionButton: ReactionButton!{
        didSet {
            reactionButton.reactionSelector = ReactionSelector()
            reactionButton.reactionSelector?.setReactions(self.createReactions())    
       }

func createReactions() -> [Reaction] {
        var reactionArray = [Reaction]()
        let like = Reaction(id: "1", title: "Like", color: .red, icon: UIImage(named: "myIcon.png")!)
       reactionArray = [like]
       return reactionArray
}

Reactions pop-up view not showing in UITableviewcell

I'm trying to implement this into UITableviewCell so, it can work like Facebook. But unfortunately unable to get popup in cell. Whereas if I'm implementing it in UIViewController simply than it works fine.
Can anyone help-me out with this?

Change Reaction Icons?

Is there a way to change the reaction icons? In other words, how do I change "Like", "Love", "Haha", "Wow", or "Angry"?

Button + Selector

How do I know when the reaction changed on a button? Even if that's triggered from a selector?

New Feature

Hey I was wondering if you would be able to add in a feature to this framework.

Introduce spectral emotions.

disable long press facebookReactionButton

Great job, is there a way to disable the long press animation of the facebookReactionButton, I only want to enable the like and dislike, no the ReactionSummary when I pressed for a long time.

How to set default Reaction Button ?

My code:

private let button = ReactionButton()
button.reaction = Reaction.facebook.sad

But by default, it is still like.
And there's one more problem. I want to set the time when ReactionSelector displays to 500ms, what should I do?

Help me, Please

I got some issue when I update your framework.

I found that below is code in your old version, and in the new version it is changed.

import UIKit

/// Default implementation of the facebook reactions.
extension Reaction {
  /// Struct which defines the standard facebook reactions.
  public struct facebook {

  public static var count:Int = 0
    /// The facebook's "like" reaction.
    
   
    public static var like: Reaction {
        return reactionWithId("1",name: "like",count:count)
    }

    /// The facebook's "love" reaction.
    public static var handpressed: Reaction {
      return reactionWithId("8",name: "handpressed",count:count)
    }

    /// The facebook's "haha" reaction.
    public static var openhand: Reaction {
      return reactionWithId("3",name: "openhand",count:count)
    }

    /// The facebook's "wow" reaction.
    public static var okhand: Reaction {
      return reactionWithId("4",name: "okhand",count:count)
    }

    /// The facebook's "sad" reaction.
    public static var smilingface: Reaction {
        return reactionWithId("2",name: "smiling-face",count:count)
    }

    /// The facebook's "sad" reaction.
    public static var surprised: Reaction {
        return reactionWithId("6",name: "surprised",count:count)
    }

    /// The facebook's "sad" reaction.
    public static var grinningface: Reaction {
        return reactionWithId("5",name: "grinning-face",count:count)
    }

    /// The facebook's "sad" reaction.
    public static var crying: Reaction {
      return reactionWithId("9",name: "crying",count:count)
    }

    /// The facebook's "angry" reaction.
    public static var pouting: Reaction {
      return reactionWithId("7",name: "pouting",count:count)
    }

    /// The facebook's "angry" reaction.
    public static var usaflag: Reaction {
        return reactionWithId("10",name: "usa-flag",count:count)
    }

    /// The list of standard facebook reactions in this order: `.like`, `.love`, `.haha`, `.wow`, `.sad`, `.angry`.
//    public static let all: [Reaction] = [facebook.like, facebook.love, facebook.haha, facebook.wow,facebook.smilingface,facebook.surprised,facebook.angry,facebook.grinningface,facebook.sad,facebook.usaflag]

    public static let all: [Reaction] = [facebook.like,facebook.smilingface,facebook.openhand,facebook.okhand,facebook.grinningface,facebook.surprised,facebook.pouting,facebook.handpressed,facebook.crying,facebook.usaflag]
    
    
    // MARK: - Convenience Methods

    private static func reactionWithId(_ id: String,name:String) -> Reaction {
      var color: UIColor            = .black
      var alternativeIcon: UIImage? = nil

      switch name {
      case "like":
        color = UIColor(red: 1/255.0, green:158/255.0, blue: 92/255.0, alpha: 1)
        alternativeIcon = imageWithName("like-template").withRenderingMode(.alwaysTemplate)
      case "love":
        color = UIColor(red: 0.93, green: 0.23, blue: 0.33, alpha: 1)
      case "angry":
        color = UIColor(red: 0.96, green: 0.37, blue: 0.34, alpha: 1)
      default:
        color = UIColor(red: 0.99, green: 0.84, blue: 0.38, alpha: 1)
      }

      return Reaction(id: id, title: name.localized(from: "FacebookReactionLocalizable"), color: color, icon: imageWithName(name), alternativeIcon: alternativeIcon)
    }
    private static func reactionWithId(_ id: String,name:String,count:Int) -> Reaction {
        var color: UIColor            = .black
        var alternativeIcon: UIImage? = nil

        switch name {
        case "like":
            color = UIColor(red: 1/255.0, green:158/255.0, blue: 92/255.0, alpha: 1)
            alternativeIcon = imageWithName("like-template").withRenderingMode(.alwaysTemplate)
        case "love":
            color = UIColor(red: 0.93, green: 0.23, blue: 0.33, alpha: 1)
        case "angry":
            color = UIColor(red: 0.96, green: 0.37, blue: 0.34, alpha: 1)
        default:
            color = UIColor(red: 0.99, green: 0.84, blue: 0.38, alpha: 1)
        }

        return Reaction(id: id, title: name.localized(from: "FacebookReactionLocalizable"), color: color, icon: imageWithName(name), alternativeIcon: alternativeIcon,count:count)
    }

    private static func imageWithName(_ name: String) -> UIImage {
      return UIImage(named: name, in: .reactionsBundle(), compatibleWith: nil)!
    }
  }
}

But when I move to your old tag file version like 1.0.0 and 2.0.0. All have the same code in this file. It looks like you haven't maintained all the version. That's why you have same code in all the version.
Correct me if I'm wrong.

Application become unresponsive

We have 'ReactionSelector' in a TableView cell. If the first-cell like button is nearby to the navigation bar (we are using one view as navigation bar), 'ReactionSelector' appears above the bar and dismiss won't work. So, the full app becomes unresponsive including the tableview. Please let me know is there anything we can do for this issue ? Can we show ReactionSelector on bottom ?

Button does not work inside StackView

I placed a ReactionButton (programmatically and storyboard), and it has errors when placing button under a stackView;
Screen Shot 2020-11-02 at 1 04 54 AM
Only the "Like" icon above is displayed, and the text is missing. it is also unresponsive to click events. Please help!

Image Edge Insets?

Is there a way to set the image edge insets for the reaction button? I'm trying to set an image for the reaction button with a 100 by 25 point frame. But, the image is not filling the button's entire frame, even though it has the same pixels when exported in Sketch as a PNG file.

Conflicting UILongPressGestureRecognizer with Reactions Button.

I have a Reactions Button that's added to a view controller's view. But, when the view has a UILongPressGestureRecognizer, also in the view, it seems to override the Reactions' selector methods where it shows the reactions. Is there a work around for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.