Skip to content

Commit

Permalink
Merge pull request #57 from shichimitoucarshi/fix/package
Browse files Browse the repository at this point in the history
FIX
  • Loading branch information
keisukeYamagishi authored Oct 27, 2024
2 parents 234832b + 71c3d71 commit 8296a06
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 15 deletions.
67 changes: 67 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/ClimbBar.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ClimbBar"
BuildableName = "ClimbBar"
BlueprintName = "ClimbBar"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ClimbBar"
BuildableName = "ClimbBar"
BlueprintName = "ClimbBar"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
18 changes: 11 additions & 7 deletions ClimbBarExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -26,6 +26,7 @@
907E60CC2A9774C9001F6A11 /* ClimbBar.h in Headers */ = {isa = PBXBuildFile; fileRef = 907E60C52A9774C9001F6A11 /* ClimbBar.h */; };
907E60CD2A9774C9001F6A11 /* ClimbState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907E60C62A9774C9001F6A11 /* ClimbState.swift */; };
907E60CF2A9774C9001F6A11 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907E60C82A9774C9001F6A11 /* Configuration.swift */; };
90D1A4892C242E50000BE8C3 /* NumberOfSelectedItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D1A4882C242E50000BE8C3 /* NumberOfSelectedItems.swift */; };
C74EF9A32294ED0400706FDA /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C74EF9A22294ED0400706FDA /* WebKit.framework */; };
C79EBF9F2282A60100B2E0CB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C79EBF9E2282A60100B2E0CB /* AppDelegate.swift */; };
C79EBFA62282A60200B2E0CB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C79EBFA52282A60200B2E0CB /* Assets.xcassets */; };
Expand Down Expand Up @@ -79,6 +80,7 @@
907E60C62A9774C9001F6A11 /* ClimbState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClimbState.swift; sourceTree = "<group>"; };
907E60C72A9774C9001F6A11 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
907E60C82A9774C9001F6A11 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
90D1A4882C242E50000BE8C3 /* NumberOfSelectedItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberOfSelectedItems.swift; sourceTree = "<group>"; };
C74EF9A22294ED0400706FDA /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
C79EBF9B2282A60100B2E0CB /* ClimbBarExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ClimbBarExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
C79EBF9E2282A60100B2E0CB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,6 +137,7 @@
90208F6B2584D6F900F01CA3 /* CollectionCell.swift */,
90208F6C2584D6F900F01CA3 /* CollectionViewController.swift */,
90208F7E2584D71E00F01CA3 /* CollectionView.storyboard */,
90D1A4882C242E50000BE8C3 /* NumberOfSelectedItems.swift */,
);
path = CollectionView;
sourceTree = "<group>";
Expand Down Expand Up @@ -364,6 +367,7 @@
C79EBF9F2282A60100B2E0CB /* AppDelegate.swift in Sources */,
90208F892584D83800F01CA3 /* SceneDelegate.swift in Sources */,
90208F742584D6F900F01CA3 /* WebViewController.swift in Sources */,
90D1A4892C242E50000BE8C3 /* NumberOfSelectedItems.swift in Sources */,
90208F722584D6F900F01CA3 /* CollectionCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -455,7 +459,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = ClimbBarExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -512,7 +516,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = ClimbBarExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -531,7 +535,7 @@
DEVELOPMENT_TEAM = D3DW67HS9F;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = ClimbBarExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -553,7 +557,7 @@
DEVELOPMENT_TEAM = D3DW67HS9F;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = ClimbBarExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -583,7 +587,7 @@
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = Sources/ClimbBar/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -621,7 +625,7 @@
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = Sources/ClimbBar/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
import UIKit

final class CollectionCell: UICollectionViewCell {
@IBOutlet var countLabel: UILabel!
@IBOutlet var icon: UIImageView!
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="xaQ-3Z-1Df">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="xaQ-3Z-1Df">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="collection view cell content view" minToolsVersion="11.0"/>
Expand Down Expand Up @@ -38,20 +38,34 @@
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="rtm-Xd-8gT">
<rect key="frame" x="0.0" y="0.0" width="125" height="125"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Hum-hJ-pPX">
<rect key="frame" x="95" y="10" width="20" height="20"/>
<color key="backgroundColor" systemColor="linkColor"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="ejU-8c-gbu"/>
<constraint firstAttribute="width" secondItem="Hum-hJ-pPX" secondAttribute="height" multiplier="1:1" id="ld2-g5-CP9"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="rtm-Xd-8gT" firstAttribute="leading" secondItem="Nrm-1V-hLw" secondAttribute="leading" id="2LA-jv-Gyd"/>
<constraint firstAttribute="bottom" secondItem="rtm-Xd-8gT" secondAttribute="bottom" id="33y-Oi-R7x"/>
<constraint firstItem="rtm-Xd-8gT" firstAttribute="leading" secondItem="Nrm-1V-hLw" secondAttribute="leading" id="F1F-kC-VVp"/>
<constraint firstAttribute="trailing" secondItem="rtm-Xd-8gT" secondAttribute="trailing" id="O34-bh-uN9"/>
<constraint firstAttribute="bottom" secondItem="rtm-Xd-8gT" secondAttribute="bottom" id="OyU-Le-qxe"/>
<constraint firstAttribute="trailing" secondItem="Hum-hJ-pPX" secondAttribute="trailing" constant="10" id="WLP-eP-DmK"/>
<constraint firstItem="Hum-hJ-pPX" firstAttribute="top" secondItem="Nrm-1V-hLw" secondAttribute="top" constant="10" id="Wc8-PS-UGO"/>
<constraint firstItem="rtm-Xd-8gT" firstAttribute="top" secondItem="Nrm-1V-hLw" secondAttribute="top" id="drj-mY-PNg"/>
<constraint firstAttribute="trailing" secondItem="rtm-Xd-8gT" secondAttribute="trailing" id="hkX-K7-gj2"/>
<constraint firstItem="rtm-Xd-8gT" firstAttribute="top" secondItem="Nrm-1V-hLw" secondAttribute="top" id="yql-EL-pfp"/>
</constraints>
</collectionViewCellContentView>
<size key="customSize" width="125" height="125"/>
<connections>
<outlet property="countLabel" destination="Hum-hJ-pPX" id="lCx-rV-9nc"/>
<outlet property="icon" destination="rtm-Xd-8gT" id="dod-JP-bLG"/>
</connections>
</collectionViewCell>
Expand Down Expand Up @@ -101,6 +115,9 @@
</scene>
</scenes>
<resources>
<systemColor name="linkColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class CollectionViewController: UIViewController {
@IBOutlet var collectionView: UICollectionView!
@IBOutlet var navigationBar: UINavigationBar!
private var climbBar: ClimbBar!
private var selectedCount: NumberOfSelectedItems = NumberOfSelectedItems()

var thirdOfTheScreen: CGFloat {
view.frame.size.width / 3 - 2
Expand Down Expand Up @@ -80,6 +81,17 @@ extension CollectionViewController: UICollectionViewDataSource {
else {
return UICollectionViewCell()
}

cell.countLabel.clipsToBounds = true
cell.countLabel.layer.cornerRadius = 10

if selectedCount.isSelectedItem(indexPath: indexPath) {
cell.countLabel.isHidden = false
cell.countLabel.text = selectedCount.getItem(indexPath)
} else {
cell.countLabel.isHidden = true
}

cell.icon.image = #imageLiteral(resourceName: "smokin")
return cell
}
Expand All @@ -95,3 +107,12 @@ extension CollectionViewController: UICollectionViewDelegateFlowLayout {
cellSize
}
}

// MARK: UICollectionViewDelegate

extension CollectionViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedCount.didSelectedItem(indexPath: indexPath)
collectionView.reloadData()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// NumberOfSelectedItems.swift
// ClimbBarExample
//
// Created by keisuke yamagishi on 2024/06/20.
// Copyright © 2024 Shichimitoucarashi. All rights reserved.
//

import Foundation

class NumberOfSelectedItems {

struct Item {
let index: IndexPath
var count: Int
}

var selectedOfNumber = 0
var selectedCells: [IndexPath] = []
var selectedItems: [Item] = []

func isSelectedItem(indexPath: IndexPath) -> Bool {
selectedCells.contains(indexPath)
}

func didSelectedItem(indexPath: IndexPath) {
if !selectedCells.contains(indexPath),
selectedCells.count < 4
{
selectedCells.append(indexPath)
selectedItems.append(Item(index: indexPath,
count: selectedOfNumber))
selectedOfNumber += 1
} else {
if let index = getIndex(indexPath: indexPath) {
selectedCells.remove(at: index)
selectedItems.remove(at: index)

selectedItems.sort {
$0.count < $1.count
}

var count = 0
var items: [Item] = []
selectedItems.forEach {
items.append(Item(index: $0.index, count: count))
count += 1
}

selectedItems = items

selectedOfNumber -= 1

} else {

}
}
}

func getItem(_ indexPath: IndexPath) -> String? {
for index in 0 ..< selectedItems.count {
let selectedItem = selectedItems[index]
if selectedItem.index == indexPath {
return "\(selectedItem.count)"
}
}
return nil
}

private func getIndex(indexPath: IndexPath) -> Int? {
for index in 0 ..< selectedCells.count {
let selectedIndexPath = selectedCells[index]
if selectedIndexPath == indexPath {
return index
}
}
return nil
}
}
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let package = Package(
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "ClimbBar",
targets: ["ClimbBar"]),
targets: ["ClimbBar"]
),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -21,6 +22,7 @@ let package = Package(
),
.testTarget(
name: "ClimbBarTests",
dependencies: ["ClimbBar"]),
dependencies: ["ClimbBar"]
),
]
)
1 change: 0 additions & 1 deletion Sources/ClimbBar/ClimbBar.State+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation

public extension ClimbBar.State {

/*
* scrollable object`s offset y
*/
Expand Down
5 changes: 3 additions & 2 deletions Sources/ClimbBar/ClimbBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ClimbBar: NSObject {
public init(configurations: Configuration,
scrollable: UIScrollView)
{
self.configuration = configurations
configuration = configurations
self.scrollable = scrollable
previousState = configuration.compact
defaultContentOffset = CGPoint(x: 0, y: -configuration.normal)
Expand All @@ -68,7 +68,7 @@ public class ClimbBar: NSObject {
setup(configurations)
}

private func setup(_ conf: Configuration) {
private func setup(_: Configuration) {
scrollable.panGestureRecognizer.addTarget(self, action: #selector(handleGesture(_:)))
if scrollable.contentInsetAdjustmentBehavior == .never {
setScrollable(contentInset: defaultInset,
Expand Down Expand Up @@ -110,4 +110,5 @@ public class ClimbBar: NSObject {
}
}
}

// swiftlint:enable all
Loading

0 comments on commit 8296a06

Please sign in to comment.