Skip to content

Commit

Permalink
优化内部Action执行流程
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed Jul 7, 2022
1 parent 4fd2f3e commit 5246643
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion AttributedString.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AttributedString"
s.version = "3.3.0"
s.version = "3.3.1"
s.summary = "基于Swift字符串插值快速构建你想要的富文本, 支持点击按住等事件获取, 支持多种类型过滤"

s.homepage = "https://github.com/lixiang1994/AttributedString"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,46 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Demo-Watch WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Demo-Watch WatchKit App">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = B9D8DJR5J5;
DEVELOPMENT_TEAM = 8G74YECJ4Z;
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
6 changes: 3 additions & 3 deletions Demo/Demo/Details/ActionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ActionViewController: UIViewController {
This is \("Long Press", .font(.systemFont(ofSize: 30)), .action(.press, pressed))
Please \("custom", .font(.systemFont(ofSize: 30)), .action(custom)).
Please \("custom highlight style", .font(.systemFont(ofSize: 30)), .action(custom)).
Please custom -> \(.image(#imageLiteral(resourceName: "swift-icon"), .original(.center)), action: custom).
Expand All @@ -71,9 +71,9 @@ class ActionViewController: UIViewController {
This is \("Long Press", .font(.systemFont(ofSize: 30)), .action(.press, pressed))
Please \("custom", .font(.systemFont(ofSize: 30)), .action(custom)).
Please \("custom highlight style", .font(.systemFont(ofSize: 30)), .action(custom)).
Please custom -> \(.image(#imageLiteral(resourceName: "swift-icon"), .original(.center)), action: custom).
Please custom highlight style -> \(.image(#imageLiteral(resourceName: "swift-icon"), .original(.center)), action: custom).
"""
}
Expand Down
32 changes: 8 additions & 24 deletions Sources/Extension/UIKit/ActionQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,21 @@ class ActionQueue {

private var action: Handle?

private var lock: Int = 0

func next(_ lock: Int) {
self.lock = lock
switch lock {
case 1:
guard let handle = action else { return }
handle()
next(0)

default:
action = nil
}
}

func began(_ handle: Handle) {
handle()
next(1)
}

func action(_ handle: @escaping Handle) {
if lock == 1 {
handle()
} else {
action = handle
}
action = handle
}

func ended(_ handle: @escaping Handle) {
action?()
handle()
}

func ended(_ handle: Handle) {
func cancelled(_ handle: @escaping Handle) {
action = nil
handle()
next(0)
}
}
2 changes: 1 addition & 1 deletion Sources/Extension/UIKit/UILabel/UILabelExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ extension UILabel {
return
}
// 保证 touchesBegan -> Action -> touchesEnded 的调用顺序
ActionQueue.main.ended {
ActionQueue.main.cancelled {
self.touched = nil
self.attributedText = touched.0.value
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extension/UIKit/UITextViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ extension UITextView {
return
}
// 保证 touchesBegan -> Action -> touchesEnded 的调用顺序
ActionQueue.main.ended {
ActionQueue.main.cancelled {
self.touched = nil
self.attributedText = touched.0.value
self.layout()
Expand Down

0 comments on commit 5246643

Please sign in to comment.