Skip to content

Commit

Permalink
Merge pull request #19 from surfstudio/package-of-new-utils
Browse files Browse the repository at this point in the history
Package of new utils
  • Loading branch information
Alexandr Kravchenkov authored Jan 10, 2019
2 parents c0bd71b + 42dbcbc commit 88ba545
Show file tree
Hide file tree
Showing 12 changed files with 674 additions and 41 deletions.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pod 'SurfUtils/$UTIL_NAME$', :git => "https://github.com/surfstudio/iOS-Utils.gi
- [JailbreakDetect](#jailbreakdetect) - позволяет определить наличие root на девайсе.
- [VibrationFeedbackManager](#vibrationfeedbackmanager) - позволяет воспроизвести вибрацию на устройстве.
- [QueryStringBuilder](#querystringbuilder) - построение строки с параметрами из словаря
- [BlurBuilder](#blurbuilder) - упрощение работы с blur-эффектом
- [RouteMeasurer](#routemeasurer) - вычисление расстояния между двумя координатами
- [SettingsRouter](#settingsrouter) - позволяет выполнить переход в настройки приложения/устройства
- [AdvancedNavigationStackManagement](#advancednavigationstackmanagement) - расширенная версия методов push/pop у UINavigationController
- [WordDeclinationSelector](#worddeclinationselector) - позволяет получить нужное склонение слова
- [ItemsScrollManager](#itemsscrollmanager) - менеджер для поэлементного скролла карусели


## Утилиты
Expand Down Expand Up @@ -65,6 +71,85 @@ let dict: [String: Any] = ["key1": "value1", "key2": 2.15, "key3": true]
let queryString = dict.toQueryString()
```

### BlurBuilder

Утилита для упрощения добавления стандартного блюра на какое-либо View, позволяет управлять стилем и цветом блюра.

Пример:
```Swift
bluredView.addBlur(color: UIColor.white.withAlphaComponent(0.1), style: .light)
```

### RouteMeasurer

Утилита для вычисления расстояния между двумя точками, как напрямую, так и с учетом возможного маршрута. Помимо прочего, предоставляет метод для форматирования результата.

Пример:
```Swift
RouteMeasurer.calculateDistance(between: firstCoordinate, and: secondCoordinate) { (distance) in
guard let distance = distance else {
return
}
let formattedDistance = RouteMeasurer.formatDistance(distance, meterPattern: "м", kilometrPatter: "км"))
}
```

### SettingsRouter

Утилита для упрощения перехода к настройкам приложения или к конкретному разделу настроек устройства.

Пример:
```Swift
SettingsRouter.openDeviceSettings()
```

### AdvancedNavigationStackManagement

Данная утилита предоставляет возможность вызова методов push и pop у UINavigationController с последующим вызывом completion-замыкания после завершения действия.

Пример:
```Swift
navigationController?.pushViewController(controller, animated: true, completion: {
print("do something else")
})
```

### WordDeclinationSelector

Утилита, позволяющая получить верное склонение слова в зависимости от числа элементов.

Пример:
```Swift
let correctForm = WordDeclinationSelector.declineWord(for: 6, from: WordDeclensions("день", "дня", "дней"))
```

### ItemsScrollManager

Утилита для так называемого "порционного скролла".
Очень часто в проекте необходимо реализовать так называемую "карусель", где представлены некоторые элементы, просматривать которые можно посредством горизонтального скролла. При этом очень часто требуется, чтобы после скролла такой карусели она автоматически подскралливалась к какому-либо элементу, а не застывала на полпути, обрезая элементы в карусели.
Данная утилита предназначена для того, чтобы в левой части экрана всегда находилось начало какого-либо элемента.

Пример:
```Swift
// Создаем менеджер, указывая ширину ячейки карусели, расстояние между ячейками, а также отступы для секции UICollectionView с каруселью
scrollManager = ItemsScrollManager(cellWidth: 200,
cellOffset: 10,
insets: UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16))

// После чего необходимо добавить вызовы следующих методов в методы UIScrollViewDelegate
extension ViewController: UIScrollViewDelegate {

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
scrollManager?.setTargetContentOffset(targetContentOffset, for: scrollView)
}

func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
scrollManager?.setBeginDraggingOffset(scrollView.contentOffset.x)
}

}
```

## Версионирование

В качестве принципа версионирования используется [Семантическое версионирования (Semantic Versioning)](https://semver.org/).
Expand Down
32 changes: 31 additions & 1 deletion SurfUtils.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SurfUtils"
s.version = "4.0.0"
s.version = "5.0.0"
s.summary = "Contains a set of utils in subspecs"
s.description = <<-DESC
Contains:
Expand Down Expand Up @@ -38,4 +38,34 @@ Pod::Spec.new do |s|
sp.framework = 'Foundation'
end

s.subspec 'BlurBuilder' do |sp|
sp.source_files = 'Utils/Utils/UIView/UIView+BlurBuilder.swift'
sp.framework = 'UIKit'
end

s.subspec 'RouteMeasurer' do |sp|
sp.source_files = 'Utils/Utils/RouteMeasurer/RouteMeasurer.swift'
sp.framework = 'MapKit'
end

s.subspec 'SettingsRouter' do |sp|
sp.source_files = 'Utils/Utils/SettingsRouter/SettingsRouter.swift'
sp.framework = 'Foundation'
end

s.subspec 'AdvancedNavigationStackManagement' do |sp|
sp.source_files = 'Utils/Utils/UINavigationController/UINavigationController+AdvancedNavigationStackManagement.swift'
sp.framework = 'UIKit'
end

s.subspec 'WordDeclinationSelector' do |sp|
sp.source_files = 'Utils/Utils/WordDeclinationSelector/WordDeclinationSelector.swift'
sp.framework = 'Foundation'
end

s.subspec 'ItemsScrollManager' do |sp|
sp.source_files = 'Utils/Utils/ItemsScrollManager/ItemsScrollManager.swift'
sp.framework = 'UIKit'
end

end
84 changes: 80 additions & 4 deletions Utils/Utils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
/* Begin PBXBuildFile section */
18F2361421D2150200169AC9 /* Dictionary+QueryStringBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18F2361321D2150200169AC9 /* Dictionary+QueryStringBuilder.swift */; };
4F3ED9E9211C27CF0030DD45 /* Utils.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4F3ED9DF211C27CF0030DD45 /* Utils.framework */; };
4F3ED9EE211C27CF0030DD45 /* UtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3ED9ED211C27CF0030DD45 /* UtilsTests.swift */; };
4F3ED9F0211C27CF0030DD45 /* Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F3ED9E2211C27CF0030DD45 /* Utils.h */; settings = {ATTRIBUTES = (Public, ); }; };
4F3ED9FC211C27FD0030DD45 /* String+Attributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3ED9FB211C27FD0030DD45 /* String+Attributes.swift */; };
80437D26214045EF0095A8D0 /* JailbreakDetect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80437D25214045EF0095A8D0 /* JailbreakDetect.swift */; };
902C67EC21E4D20B007B13CC /* ItemsScrollManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 902C67EB21E4D20B007B13CC /* ItemsScrollManager.swift */; };
902CA34121E7331E00396923 /* UIView+BlurBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 902CA34021E7331E00396923 /* UIView+BlurBuilder.swift */; };
907F0FE321DCD20C001CCB07 /* UINavigationController+AdvancedNavigationStackManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907F0FE221DCD20C001CCB07 /* UINavigationController+AdvancedNavigationStackManagement.swift */; };
907F0FE621DCD3A0001CCB07 /* SettingsRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907F0FE521DCD3A0001CCB07 /* SettingsRouter.swift */; };
907F0FEC21DCD7E1001CCB07 /* RouteMeasurer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907F0FEB21DCD7E1001CCB07 /* RouteMeasurer.swift */; };
907F0FEF21DCDB43001CCB07 /* WordDeclinationSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 907F0FEE21DCDB43001CCB07 /* WordDeclinationSelector.swift */; };
90C101C821E0B1E0002E8E65 /* WordDeclinationSelectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C101C721E0B1E0002E8E65 /* WordDeclinationSelectorTests.swift */; };
90C101CA21E0B62D002E8E65 /* RouteMeasurerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90C101C921E0B62D002E8E65 /* RouteMeasurerTests.swift */; };
E9B0630A2146924A0080C391 /* VibrationFeedbackManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9B063092146924A0080C391 /* VibrationFeedbackManager.swift */; };
E9B0630C214692C30080C391 /* UIDevice+hasTapticEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9B0630B214692C30080C391 /* UIDevice+hasTapticEngine.swift */; };
E9B0630E214693160080C391 /* UIDevice+hasHapticFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9B0630D214693160080C391 /* UIDevice+hasHapticFeedback.swift */; };
Expand All @@ -35,10 +42,17 @@
4F3ED9E2211C27CF0030DD45 /* Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = "<group>"; };
4F3ED9E3211C27CF0030DD45 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4F3ED9E8211C27CF0030DD45 /* UtilsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UtilsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4F3ED9ED211C27CF0030DD45 /* UtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsTests.swift; sourceTree = "<group>"; };
4F3ED9EF211C27CF0030DD45 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4F3ED9FB211C27FD0030DD45 /* String+Attributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Attributes.swift"; sourceTree = "<group>"; };
80437D25214045EF0095A8D0 /* JailbreakDetect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JailbreakDetect.swift; sourceTree = "<group>"; };
902C67EB21E4D20B007B13CC /* ItemsScrollManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsScrollManager.swift; sourceTree = "<group>"; };
902CA34021E7331E00396923 /* UIView+BlurBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+BlurBuilder.swift"; sourceTree = "<group>"; };
907F0FE221DCD20C001CCB07 /* UINavigationController+AdvancedNavigationStackManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+AdvancedNavigationStackManagement.swift"; sourceTree = "<group>"; };
907F0FE521DCD3A0001CCB07 /* SettingsRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRouter.swift; sourceTree = "<group>"; };
907F0FEB21DCD7E1001CCB07 /* RouteMeasurer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteMeasurer.swift; sourceTree = "<group>"; };
907F0FEE21DCDB43001CCB07 /* WordDeclinationSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordDeclinationSelector.swift; sourceTree = "<group>"; };
90C101C721E0B1E0002E8E65 /* WordDeclinationSelectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordDeclinationSelectorTests.swift; sourceTree = "<group>"; };
90C101C921E0B62D002E8E65 /* RouteMeasurerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteMeasurerTests.swift; sourceTree = "<group>"; };
E9B063092146924A0080C391 /* VibrationFeedbackManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VibrationFeedbackManager.swift; sourceTree = "<group>"; };
E9B0630B214692C30080C391 /* UIDevice+hasTapticEngine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+hasTapticEngine.swift"; sourceTree = "<group>"; };
E9B0630D214693160080C391 /* UIDevice+hasHapticFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+hasHapticFeedback.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,9 +108,15 @@
isa = PBXGroup;
children = (
18F2361221D214CC00169AC9 /* Dictionary */,
902C67EA21E4D1EF007B13CC /* ItemsScrollManager */,
80437D24214045B30095A8D0 /* JailbreakDetect */,
907F0FEA21DCD7C6001CCB07 /* RouteMeasurer */,
907F0FE421DCD375001CCB07 /* SettingsRouter */,
4F3ED9FA211C27E80030DD45 /* String */,
907F0FE121DCD1DB001CCB07 /* UINavigationController */,
902CA33F21E732F700396923 /* UIView */,
E9B06306214691F30080C391 /* VibrationFeedbackManager */,
907F0FED21DCDB1F001CCB07 /* WordDeclinationSelector */,
4F3ED9E2211C27CF0030DD45 /* Utils.h */,
4F3ED9E3211C27CF0030DD45 /* Info.plist */,
);
Expand All @@ -106,7 +126,8 @@
4F3ED9EC211C27CF0030DD45 /* UtilsTests */ = {
isa = PBXGroup;
children = (
4F3ED9ED211C27CF0030DD45 /* UtilsTests.swift */,
90C101C921E0B62D002E8E65 /* RouteMeasurerTests.swift */,
90C101C721E0B1E0002E8E65 /* WordDeclinationSelectorTests.swift */,
4F3ED9EF211C27CF0030DD45 /* Info.plist */,
);
path = UtilsTests;
Expand All @@ -128,6 +149,54 @@
path = JailbreakDetect;
sourceTree = "<group>";
};
902C67EA21E4D1EF007B13CC /* ItemsScrollManager */ = {
isa = PBXGroup;
children = (
902C67EB21E4D20B007B13CC /* ItemsScrollManager.swift */,
);
path = ItemsScrollManager;
sourceTree = "<group>";
};
902CA33F21E732F700396923 /* UIView */ = {
isa = PBXGroup;
children = (
902CA34021E7331E00396923 /* UIView+BlurBuilder.swift */,
);
path = UIView;
sourceTree = "<group>";
};
907F0FE121DCD1DB001CCB07 /* UINavigationController */ = {
isa = PBXGroup;
children = (
907F0FE221DCD20C001CCB07 /* UINavigationController+AdvancedNavigationStackManagement.swift */,
);
path = UINavigationController;
sourceTree = "<group>";
};
907F0FE421DCD375001CCB07 /* SettingsRouter */ = {
isa = PBXGroup;
children = (
907F0FE521DCD3A0001CCB07 /* SettingsRouter.swift */,
);
path = SettingsRouter;
sourceTree = "<group>";
};
907F0FEA21DCD7C6001CCB07 /* RouteMeasurer */ = {
isa = PBXGroup;
children = (
907F0FEB21DCD7E1001CCB07 /* RouteMeasurer.swift */,
);
path = RouteMeasurer;
sourceTree = "<group>";
};
907F0FED21DCDB1F001CCB07 /* WordDeclinationSelector */ = {
isa = PBXGroup;
children = (
907F0FEE21DCDB43001CCB07 /* WordDeclinationSelector.swift */,
);
path = WordDeclinationSelector;
sourceTree = "<group>";
};
E9B06306214691F30080C391 /* VibrationFeedbackManager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -248,21 +317,28 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
907F0FEC21DCD7E1001CCB07 /* RouteMeasurer.swift in Sources */,
18F2361421D2150200169AC9 /* Dictionary+QueryStringBuilder.swift in Sources */,
E9B063102147AECC0080C391 /* UIDevice+feedbackType.swift in Sources */,
902C67EC21E4D20B007B13CC /* ItemsScrollManager.swift in Sources */,
E9B0630A2146924A0080C391 /* VibrationFeedbackManager.swift in Sources */,
907F0FE621DCD3A0001CCB07 /* SettingsRouter.swift in Sources */,
E9B0630C214692C30080C391 /* UIDevice+hasTapticEngine.swift in Sources */,
80437D26214045EF0095A8D0 /* JailbreakDetect.swift in Sources */,
E9B0630E214693160080C391 /* UIDevice+hasHapticFeedback.swift in Sources */,
4F3ED9FC211C27FD0030DD45 /* String+Attributes.swift in Sources */,
902CA34121E7331E00396923 /* UIView+BlurBuilder.swift in Sources */,
907F0FEF21DCDB43001CCB07 /* WordDeclinationSelector.swift in Sources */,
907F0FE321DCD20C001CCB07 /* UINavigationController+AdvancedNavigationStackManagement.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
4F3ED9E4211C27CF0030DD45 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4F3ED9EE211C27CF0030DD45 /* UtilsTests.swift in Sources */,
90C101CA21E0B62D002E8E65 /* RouteMeasurerTests.swift in Sources */,
90C101C821E0B1E0002E8E65 /* WordDeclinationSelectorTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 88ba545

Please sign in to comment.