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

Added Support for React Native Projects #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ view.addSubview(bt1)

[ShineButton](https://github.com/ChadCSong/ShineButton)

## Third Party Bindings

### React Native
You may now use this library with [React Native](https://github.com/facebook/react-native) via the module [here](https://github.com/prscX/react-native-shine-button)

## **License**

WCLShineButton is released under the [MIT license](https://github.com/631106979/WCLShineButton/blob/master/LICENSE). See LICENSE for details.
2 changes: 1 addition & 1 deletion WCLShineButton.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ Pod::Spec.new do |s|
s.resources = 'WCLShineButton/WCLShineButton.bundle'
s.frameworks = "UIKit"
s.requires_arc = true

s.swift_version = '4.2'
end
10 changes: 5 additions & 5 deletions WCLShineButton/WCLShineAngleLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate {
}
let angleAnim = CABasicAnimation(keyPath: "transform.rotation")
angleAnim.duration = params.animDuration * 0.87
angleAnim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
angleAnim.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
angleAnim.fromValue = 0
angleAnim.toValue = CGFloat(params.shineTurnAngle)*CGFloat(Double.pi)/180
angleAnim.delegate = self
Expand All @@ -94,7 +94,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate {
}else {
displaylink?.frameInterval = 6
}
displaylink?.add(to: .current, forMode: .commonModes)
displaylink?.add(to: .current, forMode: RunLoop.Mode.common)
}

private func addShines() {
Expand Down Expand Up @@ -145,9 +145,9 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate {
let center = getShineCenter(angle: angle, radius: radius)
let path = UIBezierPath(arcCenter: center, radius: 0.1, startAngle: 0, endAngle: CGFloat(Double.pi)*2, clockwise: false)
anim.toValue = path.cgPath
anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
anim.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
anim.isRemovedOnCompletion = false
anim.fillMode = kCAFillModeForwards
anim.fillMode = CAMediaTimingFillMode.forwards
return anim
}

Expand All @@ -160,7 +160,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate {
flash.repeatCount = MAXFLOAT
flash.isRemovedOnCompletion = false
flash.autoreverses = true
flash.fillMode = kCAFillModeForwards
flash.fillMode = CAMediaTimingFillMode.forwards
return flash
}

Expand Down
38 changes: 33 additions & 5 deletions WCLShineButton/WCLShineButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,28 @@ public class WCLShineButton: UIControl {
}

/// button的图片
public var image: WCLShineImage = .heart {
@IBInspectable public var image: NSString = ".heart" {
willSet {
clickLayer.image = newValue
switch newValue {
case ".heart":
clickLayer.image = .heart
case ".like":
clickLayer.image = .like
case ".smile":
clickLayer.image = .smile
case ".star":
clickLayer.image = .star
default:
clickLayer.image = .heart
}
// clickLayer.image = newValue
}
}

@objc public var customImage: UIImage = UIImage() {
willSet {
let image = WCLShineImage.custom(newValue)
clickLayer.image = image
}
}

Expand All @@ -64,6 +83,11 @@ public class WCLShineButton: UIControl {
clickLayer.clicked = isSelected
}
}

@IBInspectable public var getSelection: Bool {
print("Clicked: \(clickLayer.clicked)")
return clickLayer.clicked
}

private var clickLayer = WCLShineClickLayer()

Expand All @@ -89,6 +113,7 @@ public class WCLShineButton: UIControl {
initLayers()
}

@objc
public func setClicked(_ clicked: Bool, animated: Bool = true) {
guard clicked != clickLayer.clicked else {
return
Expand Down Expand Up @@ -117,11 +142,12 @@ public class WCLShineButton: UIControl {
super.touchesEnded(touches, with: event)
if clickLayer.clicked == false {
shineLayer.endAnim = { [weak self] in
self?.clickLayer.clicked = !(self?.clickLayer.clicked ?? false)
// self?.clickLayer.clicked = !(self?.clickLayer.clicked ?? false)
self?.clickLayer.startAnim()
self?.isSelected = self?.clickLayer.clicked ?? false
// self?.isSelected = self?.clickLayer.clicked ?? false
self?.sendActions(for: .valueChanged)
}
clickLayer.clicked = true
shineLayer.startAnim()
}else {
clickLayer.clicked = !clickLayer.clicked
Expand All @@ -131,7 +157,8 @@ public class WCLShineButton: UIControl {
}

//MARK: Privater Methods
private func initLayers() {
@objc
public func initLayers() {
clickLayer.animDuration = params.animDuration/3
shineLayer.params = params
clickLayer.frame = bounds
Expand All @@ -140,3 +167,4 @@ public class WCLShineButton: UIControl {
layer.addSublayer(shineLayer)
}
}

2 changes: 1 addition & 1 deletion WCLShineButton/WCLShineClickLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WCLShineClickLayer: CALayer {
let anim = CAKeyframeAnimation(keyPath: "transform.scale")
anim.duration = animDuration
anim.values = [0.4, 1, 0.9, 1]
anim.calculationMode = kCAAnimationCubic
anim.calculationMode = CAAnimationCalculationMode.cubic
if image.isDefaultAndSelect() {
add(anim, forKey: "scale")
}else {
Expand Down
6 changes: 3 additions & 3 deletions WCLShineButton/WCLShineLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class WCLShineLayer: CALayer, CAAnimationDelegate {
let toPath = UIBezierPath(arcCenter: CGPoint.init(x: size.width/2, y: size.height/2), radius: size.width/2 * CGFloat(params.shineDistanceMultiple), startAngle: 0, endAngle: CGFloat(Double.pi) * 2.0, clockwise: false).cgPath
anim.delegate = self
anim.values = [fromPath, toPath]
anim.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)]
anim.timingFunctions = [CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)]
anim.isRemovedOnCompletion = false
anim.fillMode = kCAFillModeForwards
anim.fillMode = CAMediaTimingFillMode.forwards
shapeLayer.add(anim, forKey: "path")
if params.enableFlashing {
startFlash()
Expand Down Expand Up @@ -90,7 +90,7 @@ class WCLShineLayer: CALayer, CAAnimationDelegate {
}else {
displaylink?.frameInterval = 10
}
displaylink?.add(to: .current, forMode: .commonModes)
displaylink?.add(to: .current, forMode: RunLoop.Mode.common)
}

@objc private func flashAction() {
Expand Down