Skip to content

Commit

Permalink
Merge branch 'feature/swift4-2' into feat-update-swift-4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rnkyr authored Oct 16, 2018
2 parents 3b69761 + 1428f35 commit adaea90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
12 changes: 9 additions & 3 deletions Segmentio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = Yalantis;
TargetAttributes = {
324B603F1D33E43E0050B083 = {
Expand Down Expand Up @@ -248,12 +248,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -285,6 +287,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -302,12 +305,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -332,6 +337,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -352,7 +358,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantismobile.Segmentio;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -374,7 +380,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yalantismobile.Segmentio;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
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 = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
21 changes: 12 additions & 9 deletions Segmentio/Source/Segmentio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,25 @@ open class Segmentio: UIView {
// MARK: Move shape layer to item

fileprivate func moveShapeLayerAtContext() {
let itemWitdh = segmentioItems.enumerated().map { (index, _) -> CGFloat in
return segmentWidth(for: IndexPath(item: index, section: 0))
}
if let indicatorLayer = indicatorLayer, let options = segmentioOptions.indicatorOptions {
let item = itemInSuperview(ratio: options.ratio)

let points = Points(
item: item,
atIndex: selectedSegmentioIndex,
allItems: segmentioItems,
allItemsCellWidth: itemWitdh,
pointY: indicatorPointY(),
position: segmentioOptions.segmentPosition,
style: segmentioStyle
)

let insetX = ((points.endPoint.x - points.startPoint.x) - (item.endX - item.startX))/2
moveShapeLayer(
indicatorLayer,
startPoint: points.startPoint,
endPoint: points.endPoint,
startPoint: CGPoint(x: points.startPoint.x + insetX, y: points.startPoint.y),
endPoint: CGPoint(x: points.endPoint.x - insetX, y: points.endPoint.y),
animated: true
)
}
Expand All @@ -356,7 +359,7 @@ open class Segmentio: UIView {
let points = Points(
item: item,
atIndex: selectedSegmentioIndex,
allItems: segmentioItems,
allItemsCellWidth: itemWitdh,
pointY: bounds.midY,
position: segmentioOptions.segmentPosition,
style: segmentioStyle
Expand Down Expand Up @@ -660,16 +663,16 @@ extension Segmentio: UIScrollViewDelegate {

extension Segmentio.Points {

init(item: Segmentio.ItemInSuperview, atIndex index: Int, allItems: [SegmentioItem], pointY: CGFloat, position: SegmentioPosition, style: SegmentioStyle) {
init(item: Segmentio.ItemInSuperview, atIndex index: Int, allItemsCellWidth: [CGFloat], pointY: CGFloat, position: SegmentioPosition, style: SegmentioStyle) {
let cellWidth = item.cellFrameInSuperview.width
var startX = item.startX
var endX = item.endX
var spaceBefore: CGFloat = 0
var spaceAfter: CGFloat = 0
var i = 0
allItems.forEach { _ in
if i < index { spaceBefore += cellWidth }
if i > index { spaceAfter += cellWidth }
allItemsCellWidth.forEach { width in
if i < index { spaceBefore += width }
if i > index { spaceAfter += width }
i += 1
}
// Cell will try to position itself in the middle, unless it can't because
Expand Down

0 comments on commit adaea90

Please sign in to comment.