Skip to content

Commit

Permalink
Rewrite Haptic feedback; Supported Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramiz69 committed Jan 6, 2025
1 parent 67d5503 commit fbdb5b4
Show file tree
Hide file tree
Showing 26 changed files with 514 additions and 387 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added .github/.DS_Store
Binary file not shown.
Binary file added .github/workflows/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## [0.2.1] - 2025-01-06

### Added
- Support Swift 6.0

### Changed
- Rewrite Haptic Feedback from UIFeedbackGenerator to CoreHaptic

## [0.2.0] - 2024-04-06

### Added
Expand Down
Binary file added RKSlider/.DS_Store
Binary file not shown.
43 changes: 30 additions & 13 deletions Slider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 63;
objectVersion = 77;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -23,8 +23,10 @@
4B8DAEA12BA6A5E9005CFA82 /* CodeViewController+UIColorPickerViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8DAEA02BA6A5E9005CFA82 /* CodeViewController+UIColorPickerViewControllerDelegate.swift */; };
4B8DAEA42BA6AE54005CFA82 /* ThumbLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8DAEA22BA6ACFF005CFA82 /* ThumbLayer.swift */; };
4B8DAEA62BA6B445005CFA82 /* TextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8DAEA52BA6B445005CFA82 /* TextLayer.swift */; };
4BB580D52D2BDB97009BFA02 /* HapticManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB580D42D2BDB93009BFA02 /* HapticManager.swift */; };
4BB580D72D2BDD2B009BFA02 /* LoggerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB580D62D2BDD27009BFA02 /* LoggerManager.swift */; };
4BB580D92D2BDFDF009BFA02 /* HapticConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB580D82D2BDFDA009BFA02 /* HapticConfiguration.swift */; };
4BC808B92BC1A005001F31C8 /* Documentation.docc in Sources */ = {isa = PBXBuildFile; fileRef = 4BC808B82BC1A005001F31C8 /* Documentation.docc */; };
4BF628A12BA2B38D0093637E /* HapticConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF628922BA2B38D0093637E /* HapticConfiguration.swift */; };
4BF628A32BA2B38D0093637E /* Slider+UITouch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF628962BA2B38D0093637E /* Slider+UITouch.swift */; };
4BF628A42BA2B38D0093637E /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF628972BA2B38D0093637E /* String.swift */; };
4BF628A52BA2B38D0093637E /* SliderDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF628992BA2B38D0093637E /* SliderDelegate.swift */; };
Expand Down Expand Up @@ -75,8 +77,10 @@
4B8DAEA02BA6A5E9005CFA82 /* CodeViewController+UIColorPickerViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CodeViewController+UIColorPickerViewControllerDelegate.swift"; sourceTree = "<group>"; };
4B8DAEA22BA6ACFF005CFA82 /* ThumbLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThumbLayer.swift; sourceTree = "<group>"; };
4B8DAEA52BA6B445005CFA82 /* TextLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLayer.swift; sourceTree = "<group>"; };
4BB580D42D2BDB93009BFA02 /* HapticManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticManager.swift; sourceTree = "<group>"; };
4BB580D62D2BDD27009BFA02 /* LoggerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerManager.swift; sourceTree = "<group>"; };
4BB580D82D2BDFDA009BFA02 /* HapticConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticConfiguration.swift; sourceTree = "<group>"; };
4BC808B82BC1A005001F31C8 /* Documentation.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Documentation.docc; sourceTree = "<group>"; };
4BF628922BA2B38D0093637E /* HapticConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HapticConfiguration.swift; sourceTree = "<group>"; };
4BF628962BA2B38D0093637E /* Slider+UITouch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Slider+UITouch.swift"; sourceTree = "<group>"; };
4BF628972BA2B38D0093637E /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
4BF628992BA2B38D0093637E /* SliderDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,10 +216,19 @@
path = Manager;
sourceTree = "<group>";
};
4BB580D32D2BDB8D009BFA02 /* Managers */ = {
isa = PBXGroup;
children = (
4BB580D62D2BDD27009BFA02 /* LoggerManager.swift */,
4BB580D42D2BDB93009BFA02 /* HapticManager.swift */,
);
path = Managers;
sourceTree = "<group>";
};
4BF628932BA2B38D0093637E /* Configurations */ = {
isa = PBXGroup;
children = (
4BF628922BA2B38D0093637E /* HapticConfiguration.swift */,
4BB580D82D2BDFDA009BFA02 /* HapticConfiguration.swift */,
4B8DAE972BA6956B005CFA82 /* TrackConfiguration.swift */,
4B8DAE992BA696A8005CFA82 /* ThumbConfiguration.swift */,
4B8DAE9B2BA69A69005CFA82 /* RangeEndpointsConfiguration.swift */,
Expand Down Expand Up @@ -243,6 +256,7 @@
4BF628A02BA2B38D0093637E /* Sources */ = {
isa = PBXGroup;
children = (
4BB580D32D2BDB8D009BFA02 /* Managers */,
4BF628932BA2B38D0093637E /* Configurations */,
4BF628982BA2B38D0093637E /* Extensions */,
4BF6289A2BA2B38D0093637E /* Protocols */,
Expand Down Expand Up @@ -318,7 +332,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1530;
LastUpgradeCheck = 1610;
ORGANIZATIONNAME = "Ramiz Kichibekov";
TargetAttributes = {
4B2EB6C123C1E11E00FB91AD = {
Expand All @@ -331,16 +345,17 @@
};
};
buildConfigurationList = 4B2EB6BC23C1E11E00FB91AD /* Build configuration list for PBXProject "Slider" */;
compatibilityVersion = "Xcode 15.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 4B2EB6B823C1E11E00FB91AD;
minimizedProjectReferenceProxies = 1;
packageReferences = (
);
preferredProjectObjectVersion = 77;
productRefGroup = 4B2EB6C323C1E11F00FB91AD /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -376,18 +391,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4BB580D52D2BDB97009BFA02 /* HapticManager.swift in Sources */,
4BF628A52BA2B38D0093637E /* SliderDelegate.swift in Sources */,
4BF628A32BA2B38D0093637E /* Slider+UITouch.swift in Sources */,
4BB580D72D2BDD2B009BFA02 /* LoggerManager.swift in Sources */,
4B8DAE9C2BA69A69005CFA82 /* RangeEndpointsConfiguration.swift in Sources */,
4BF628A42BA2B38D0093637E /* String.swift in Sources */,
4B8DAE9A2BA696A8005CFA82 /* ThumbConfiguration.swift in Sources */,
4BB580D92D2BDFDF009BFA02 /* HapticConfiguration.swift in Sources */,
4BF628A82BA2B38D0093637E /* Slider.swift in Sources */,
4B8DAEA62BA6B445005CFA82 /* TextLayer.swift in Sources */,
4BC808B92BC1A005001F31C8 /* Documentation.docc in Sources */,
4BF628AA2BA2B38D0093637E /* SliderTrackLayer.swift in Sources */,
4B8DAE982BA6956B005CFA82 /* TrackConfiguration.swift in Sources */,
4B8DAEA42BA6AE54005CFA82 /* ThumbLayer.swift in Sources */,
4BF628A12BA2B38D0093637E /* HapticConfiguration.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -495,6 +512,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -554,6 +572,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 6.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -585,7 +604,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -614,15 +633,14 @@
PRODUCT_BUNDLE_IDENTIFIER = "Ramiz-Kichibekov.Slider";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
4B2EB6F423C1E5AA00FB91AD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 8AD8N54BY6;
Expand All @@ -634,15 +652,14 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Ramiz-Kichibekov.Slider-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
4B2EB6F523C1E5AA00FB91AD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 8AD8N54BY6;
Expand All @@ -654,7 +671,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Ramiz-Kichibekov.Slider-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Slider.xcodeproj/xcshareddata/xcschemes/Slider.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
LastUpgradeVersion = "1610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Binary file added Slider_Example/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions Slider_Example/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@

import UIKit

@UIApplicationMain
@main
final class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication,
Expand Down
Binary file added Slider_Example/Flows/.DS_Store
Binary file not shown.
Binary file added Slider_Example/Flows/Main/.DS_Store
Binary file not shown.
53 changes: 26 additions & 27 deletions Slider_Example/Flows/Main/Controllers/CodeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ final class CodeViewController: UIViewController {
slider.minimum = .zero
slider.value = .zero
slider.animationStyle = .default

view.addSubview(slider)
slider.translatesAutoresizingMaskIntoConstraints = false
let layoutMarginsGuide = view.layoutMarginsGuide
Expand All @@ -132,23 +133,26 @@ final class CodeViewController: UIViewController {
}

private func configureHaptic() {
slider.hapticConfiguration = .init(reachLimitValueHapticEnabled: preference.hapticPreference.reachMinMaxValues,
changeValueHapticEnabled: preference.hapticPreference.valueChanges,
changeDirectionHapticEnabled: preference.hapticPreference.directionChanges,
reachImpactGeneratorStyle: .medium,
changeValueImpactGeneratorStyle: .light)
var kind: HapticConfiguration.Kind = [.transient, .continuous]
if preference.hapticPreference.transient {
kind.insert(.transient)
} else {
kind.remove(.transient)
}
if preference.hapticPreference.continuous {
kind.insert(.continuous)
} else {
kind.remove(.continuous)
}
slider.hapticConfiguration = HapticConfiguration(kind: kind)
configurePreferenceMenu()
}

private func resetSlider() {
slider.hapticConfiguration = .init(reachLimitValueHapticEnabled: preference.hapticPreference.reachMinMaxValues,
changeValueHapticEnabled: preference.hapticPreference.valueChanges,
changeDirectionHapticEnabled: preference.hapticPreference.directionChanges,
reachImpactGeneratorStyle: .medium,
changeValueImpactGeneratorStyle: .light)
slider.thumbConfiguration = .init()
slider.maximumEndpointConfiguration = .init()
slider.minimumEndpointConfiguration = .init()
slider.hapticConfiguration = HapticConfiguration()
slider.thumbConfiguration = ThumbConfiguration()
slider.maximumEndpointConfiguration = RangeEndpointsConfiguration()
slider.minimumEndpointConfiguration = RangeEndpointsConfiguration()
}

private func configurePreferenceMenu() {
Expand Down Expand Up @@ -224,25 +228,20 @@ final class CodeViewController: UIViewController {

private func configureHapticMenu() -> UIMenu {
let hapticPreference = preference.hapticPreference
let reachAction = UIAction(title: "Reach Min/Max values",
state: hapticPreference.reachMinMaxValues ? .on : .off) { [unowned self] _ in
hapticPreference.reachMinMaxValues.toggle()
let transientAction = UIAction(title: "Transient",
state: hapticPreference.transient ? .on : .off) { [unowned self] _ in
hapticPreference.transient.toggle()
self.configureHaptic()
}
let valueChangeAction = UIAction(title: "Value changes",
state: hapticPreference.valueChanges ? .on : .off) { [unowned self] _ in
hapticPreference.valueChanges.toggle()
let continuousAction = UIAction(title: "Continuous",
state: hapticPreference.continuous ? .on : .off) { [unowned self] _ in
hapticPreference.continuous.toggle()
self.configureHaptic()
}
let directionChangeAction = UIAction(title: "Direction changes",
state: hapticPreference.directionChanges ? .on : .off) { [unowned self] _ in
hapticPreference.directionChanges.toggle()
self.configureHaptic()
}


return UIMenu(title: "Haptic",
image: UIImage(systemName: "iphone.gen3.radiowaves.left.and.right"),
children: [reachAction, valueChangeAction, directionChangeAction])
children: [transientAction, continuousAction])
}

private func configureEndpointMenu() -> UIMenu {
Expand Down Expand Up @@ -296,7 +295,7 @@ final class CodeViewController: UIViewController {
}
}

extension CATextLayerAlignmentMode: CaseIterable {
extension CATextLayerAlignmentMode: @retroactive CaseIterable {
public static var allCases: [CATextLayerAlignmentMode] {
[.left, .natural, .center, .right, .justified]
}
Expand Down
Loading

0 comments on commit fbdb5b4

Please sign in to comment.