Skip to content

Commit

Permalink
add ifmatched modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Jun 8, 2017
1 parent a0b8ce5 commit 6c7c741
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
12 changes: 2 additions & 10 deletions Hero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@
PRODUCT_NAME = Hero;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1144,7 +1143,6 @@
PRODUCT_NAME = Hero;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1164,7 +1162,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroTvOSExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1182,7 +1179,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroTvOSExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1209,7 +1205,6 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -1235,7 +1230,6 @@
PRODUCT_NAME = Hero;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1296,6 +1290,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand Down Expand Up @@ -1345,6 +1340,7 @@
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -1362,7 +1358,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1380,7 +1375,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -1396,7 +1390,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HeroExamples.app/HeroExamples";
};
name = Debug;
Expand All @@ -1412,7 +1405,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.lkzhao.HeroTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HeroExamples.app/HeroExamples";
};
name = Release;
Expand Down
9 changes: 7 additions & 2 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Sources/HeroModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,19 @@ extension HeroModifier {
}
}

/**
Apply modifiers at the start of the transition if the view is matched with another view.
Note that this will apply if a parent view is matched.
*/
public static func ifMatched(modifiers: [HeroModifier]) -> HeroModifier {
return HeroModifier { targetState in
if targetState.ifMatched == nil {
targetState.ifMatched = []
}
targetState.ifMatched!.append(contentsOf: modifiers)
}
}

/**
Use global coordinate space.

Expand Down
1 change: 1 addition & 0 deletions Sources/HeroTargetState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public struct HeroTargetState {
}
internal var beginState: HeroTargetStateWrapper?
public var beginStateIfMatched: [HeroModifier]?
public var ifMatched: [HeroModifier]?

public var position: CGPoint?
public var size: CGSize?
Expand Down
12 changes: 12 additions & 0 deletions Sources/Preprocessors/MatchPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class MatchPreprocessor: BasePreprocessor {
if let beginStateIfMatched = fvState.beginStateIfMatched {
fvState.append(.beginWith(modifiers: beginStateIfMatched))
}
applyIfMatchedSubviewModifiers(tv)
applyIfMatchedSubviewModifiers(fv)

// match is just a two-way source effect
tvState.source = id
Expand Down Expand Up @@ -80,4 +82,14 @@ class MatchPreprocessor: BasePreprocessor {
context[fv] = fvState
}
}

private func applyIfMatchedSubviewModifiers(_ view: UIView) {
if let ifMatched = context[view]?.ifMatched {
context[view]!.append(contentsOf: ifMatched)
context[view]!.ifMatched = nil
}
for view in view.subviews {
applyIfMatchedSubviewModifiers(view)
}
}
}

0 comments on commit 6c7c741

Please sign in to comment.