Skip to content

Commit

Permalink
Merge pull request #4 from TextureCommunity/muukii/fix-animation
Browse files Browse the repository at this point in the history
Supports animation for update descriptor
  • Loading branch information
muukii authored May 12, 2020
2 parents 8383039 + 6981ec5 commit c853c2f
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 150 deletions.
17 changes: 1 addition & 16 deletions Demo-GlossButtonNode/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,12 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {


var window: UIWindow? = .init()

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

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

19 changes: 0 additions & 19 deletions Demo-GlossButtonNode/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
53 changes: 0 additions & 53 deletions Demo-GlossButtonNode/SceneDelegate.swift

This file was deleted.

123 changes: 117 additions & 6 deletions Demo-GlossButtonNode/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ extension ViewController {
bodyOpacity: 1,
insets: .init(top: 16, left: 16, bottom: 16, right: 16)
),

GlossButtonDescriptor(
title: "Confirm".styled {
$0.font(.boldSystemFont(ofSize: 18))
.foregroundColor(.white)
},
image: icon,
bodyStyle: .init(layout: .horizontal(imageEdgeInsets: .init(top: 0, left: 0, bottom: 0, right: 2))),
surfaceStyle: .fill(
.init(
cornerRound: .radius(topRight: 20, topLeft: 20, bottomRight: 10, bottomLeft: 10),
backgroundColor: .gradient(
colorAndLocations: [
(0, #colorLiteral(red: 0.4375238121, green: 0.04877754301, blue: 0.4053111374, alpha: 1)),
(1, #colorLiteral(red: 0.9841937423, green: 0.3711297512, blue: 0.2100374103, alpha: 1)),
],
startPoint: .init(x: 0, y: 0),
endPoint: .init(x: 1, y: 1)
),
dropShadow: .none
)
),
bodyOpacity: 1,
insets: .init(top: 16, left: 16, bottom: 16, right: 16)
),

GlossButtonDescriptor(
title: "Confirm".styled {
Expand Down Expand Up @@ -184,7 +209,7 @@ extension ViewController {
}

self.scrollNode = VerticalScrollWrapperNode {
Self.makeList(buttonNodes: buttons)
Self.makeList(buttonNodes: buttons.map { Self.makeCell(buttonNode: $0) } + CollectionOfOne(Self.makeToggleCell()))
}

super.init()
Expand All @@ -204,14 +229,12 @@ extension ViewController {
}
}

private static func makeList(buttonNodes: [GlossButtonNode]) -> FunctionalDisplayNode {

let nodes = buttonNodes.map { makeCell(buttonNode: $0) }

private static func makeList(buttonNodes: [ASDisplayNode]) -> FunctionalDisplayNode {

return FunctionalDisplayNode { _, _ in
LayoutSpec {
VStackLayout {
nodes
buttonNodes
}
}
}
Expand All @@ -231,6 +254,94 @@ extension ViewController {
}
}
}

private static func makeToggleCell() -> FunctionalDisplayNode {

let button = GlossButtonNode()

let base = GlossButtonDescriptor(
title: nil,
image: nil,
bodyStyle: .init(layout: .horizontal(imageEdgeInsets: .init(top: 0, left: 0, bottom: 0, right: 2))),
surfaceStyle: .fill(
.init(
cornerRound: .circle,
backgroundColor: .gradient(
colorAndLocations: [
(0, #colorLiteral(red: 0.4375238121, green: 0.04877754301, blue: 0.4053111374, alpha: 1)),
(1, #colorLiteral(red: 0.9841937423, green: 0.3711297512, blue: 0.2100374103, alpha: 1)),
],
startPoint: .init(x: 0, y: 0),
endPoint: .init(x: 1, y: 1)
),
dropShadow: .none
)
),
bodyOpacity: 1,
insets: .init(top: 16, left: 16, bottom: 16, right: 16)
)

let on = GlossButtonDescriptor(
title: "A".styled {
$0.font(.boldSystemFont(ofSize: 18))
.foregroundColor(#colorLiteral(red: 0.4375238121, green: 0.04877754301, blue: 0.4053111374, alpha: 1))
},
image: nil,
bodyStyle: .init(layout: .horizontal(imageEdgeInsets: .init(top: 0, left: 0, bottom: 0, right: 2))),
surfaceStyle: .stroke(
.init(
cornerRound: .radius(16),
strokeColor: #colorLiteral(red: 0.4375238121, green: 0.04877754301, blue: 0.4053111374, alpha: 1),
borderWidth: 2,
highlightAnimation: .basic
)
),
bodyOpacity: 1,
insets: .init(top: 16, left: 16, bottom: 16, right: 16)
)

let off = GlossButtonDescriptor(
title: "BBB".styled {
$0.font(.boldSystemFont(ofSize: 18))
.foregroundColor(.white)
},
image: nil,
bodyStyle: .init(layout: .horizontal(imageEdgeInsets: .init(top: 0, left: 0, bottom: 0, right: 2))),
surfaceStyle: .fill(
.init(
cornerRound: .circle,
backgroundColor: .gradient(
colorAndLocations: [
(0, #colorLiteral(red: 0.4375238121, green: 0.04877754301, blue: 0.4053111374, alpha: 1)),
(1, #colorLiteral(red: 0.9841937423, green: 0.3711297512, blue: 0.2100374103, alpha: 1)),
],
startPoint: .init(x: 0, y: 0),
endPoint: .init(x: 1, y: 1)
),
dropShadow: .none
)
),
bodyOpacity: 1,
insets: .init(top: 16, left: 16, bottom: 16, right: 16)
)

button.setDescriptor(off, for: .normal)

var flag = false

button.onTap = { [weak button] in

flag.toggle()
if flag {
button?.setDescriptor(on, for: .normal, animated: true)
} else {
button?.setDescriptor(off, for: .normal, animated: true)
}

}

return makeCell(buttonNode: button)
}

}

Expand Down
8 changes: 4 additions & 4 deletions GlossButtonNode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
4B6F6F632452A32C00B6CC3A /* GlossButtonBodyLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6F6F592452A32C00B6CC3A /* GlossButtonBodyLayout.swift */; };
4B6F6F642452A32C00B6CC3A /* GlossButtonBlurrySurfaceNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6F6F5A2452A32C00B6CC3A /* GlossButtonBlurrySurfaceNode.swift */; };
4B6F6F6C2452AEC300B6CC3A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6F6F6B2452AEC300B6CC3A /* AppDelegate.swift */; };
4B6F6F6E2452AEC300B6CC3A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6F6F6D2452AEC300B6CC3A /* SceneDelegate.swift */; };
4B6F6F702452AEC300B6CC3A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6F6F6F2452AEC300B6CC3A /* ViewController.swift */; };
4B6F6F732452AEC300B6CC3A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B6F6F712452AEC300B6CC3A /* Main.storyboard */; };
4B6F6F752452AEC400B6CC3A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B6F6F742452AEC400B6CC3A /* Assets.xcassets */; };
Expand Down Expand Up @@ -72,7 +71,6 @@
4B6F6F5A2452A32C00B6CC3A /* GlossButtonBlurrySurfaceNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlossButtonBlurrySurfaceNode.swift; sourceTree = "<group>"; };
4B6F6F692452AEC300B6CC3A /* Demo-GlossButtonNode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Demo-GlossButtonNode.app"; sourceTree = BUILT_PRODUCTS_DIR; };
4B6F6F6B2452AEC300B6CC3A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4B6F6F6D2452AEC300B6CC3A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
4B6F6F6F2452AEC300B6CC3A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
4B6F6F722452AEC300B6CC3A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
4B6F6F742452AEC400B6CC3A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -151,7 +149,6 @@
children = (
4B2276162454A8F900F39A16 /* VerticalScrollWrapperNode.swift */,
4B6F6F6B2452AEC300B6CC3A /* AppDelegate.swift */,
4B6F6F6D2452AEC300B6CC3A /* SceneDelegate.swift */,
4B6F6F6F2452AEC300B6CC3A /* ViewController.swift */,
4B6F6F712452AEC300B6CC3A /* Main.storyboard */,
4B6F6F742452AEC400B6CC3A /* Assets.xcassets */,
Expand Down Expand Up @@ -382,7 +379,6 @@
4B6F6F702452AEC300B6CC3A /* ViewController.swift in Sources */,
4B6F6F6C2452AEC300B6CC3A /* AppDelegate.swift in Sources */,
4B2276172454A8F900F39A16 /* VerticalScrollWrapperNode.swift in Sources */,
4B6F6F6E2452AEC300B6CC3A /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -548,6 +544,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = GlossButtonNode/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -574,6 +571,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = GlossButtonNode/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -594,6 +592,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = "Demo-GlossButtonNode/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -612,6 +611,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = "Demo-GlossButtonNode/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Loading

0 comments on commit c853c2f

Please sign in to comment.