Skip to content

Commit

Permalink
add viewModel; add parameter "Index: Binding<Int>"
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAuttom committed Dec 28, 2020
1 parent 7a033aa commit 8a32251
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 623 deletions.
14 changes: 7 additions & 7 deletions ACarouselDemo/ACarouselDemo iOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ let roles = ["Luffy", "Zoro", "Sanji", "Nami", "Usopp", "Chopper", "Robin", "Fra

struct ContentView: View {

let items: [Item] = roles.map { Item(image: Image($0)) }

@State var spacing: CGFloat = 10
@State var headspace: CGFloat = 10
@State var sidesScaling: CGFloat = 0.8
Expand All @@ -29,15 +27,17 @@ struct ContentView: View {

var body: some View {
VStack {
Spacer().frame(height: 50)
ACarousel(items,
Text("\(currentIndex + 1)/\(roles.count)")
Spacer().frame(height: 40)
ACarousel(roles,
id: \.self,
index: $currentIndex,
spacing: spacing,
activeIndex: $currentIndex,
headspace: headspace,
sidesScaling: sidesScaling,
isWrap: isWrap,
autoScroll: autoScroll ? .active(time) : .inactive) { item in
item.image
autoScroll: autoScroll ? .active(time) : .inactive) { name in
Image(name)
.resizable()
.scaledToFill()
.frame(height: 300)
Expand Down
1 change: 1 addition & 0 deletions ACarouselDemo/ACarouselDemo macOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct ContentView: View {
VStack {
Spacer().frame(height: 30)
ACarousel(items,
index: .constant(2),
spacing: spacing,
headspace: headspace,
sidesScaling: sidesScaling,
Expand Down
32 changes: 0 additions & 32 deletions ACarouselDemo/ACarouselDemo macOS/Test.swift

This file was deleted.

8 changes: 2 additions & 6 deletions ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
EDC9AF3A2563982100321BC0 /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC9AF392563982100321BC0 /* Test.swift */; };
EDC9AF3F2563A19300321BC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EDF64C97256241320050A86D /* Assets.xcassets */; };
EDF64C92256241310050A86D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDF64C91256241310050A86D /* AppDelegate.swift */; };
EDF64C94256241310050A86D /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDF64C93256241310050A86D /* SceneDelegate.swift */; };
Expand All @@ -24,7 +23,6 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
EDC9AF392563982100321BC0 /* Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; };
EDF64C8E256241310050A86D /* ACarouselDemo iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ACarouselDemo iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
EDF64C91256241310050A86D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EDF64C93256241310050A86D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -121,7 +119,6 @@
EDF64D68256380F10050A86D /* Info.plist */,
EDF64D69256380F10050A86D /* ACarouselDemo_macOS.entitlements */,
EDF64D62256380F10050A86D /* Preview Content */,
EDC9AF392563982100321BC0 /* Test.swift */,
);
path = "ACarouselDemo macOS";
sourceTree = "<group>";
Expand Down Expand Up @@ -253,7 +250,6 @@
files = (
EDF64D5D256380F10050A86D /* AppDelegate.swift in Sources */,
EDF64DA425638FC50050A86D /* ContentView.swift in Sources */,
EDC9AF3A2563982100321BC0 /* Test.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -349,7 +345,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "ACarouselDemo iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -419,7 +415,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "ACarouselDemo iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A carousel view for SwiftUI

English version | [中文文档](README.zh-CN.md)
[中文文档](README.zh-CN.md)

<p align="center">
<img src='https://img.shields.io/badge/Swift-5.1-green?style=flat'>
Expand Down Expand Up @@ -43,7 +43,7 @@ Open `Xcode`, go to `File -> Swift Packages -> Add Package Dependency` and enter
You can also add `ACarousel` as a dependency to your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/JWAutumn/ACarousel", from: "0.1.3")
.package(url: "https://github.com/JWAutumn/ACarousel", from: "0.2.0")
]
```

Expand Down Expand Up @@ -78,7 +78,21 @@ struct ContentView: View {
}
}
```

or:
```swift
...
var body: some View {
ACarousel(roles, id: \.self) { name in
Image(name)
.resizable()
.scaledToFill()
.frame(height: 300)
.cornerRadius(30)
}
.frame(height: 300)
}
...
```
- Customize configuration: You can configure the corresponding parameters to customize the display style according to your needs.
```swift
/// ...
Expand Down
21 changes: 19 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`SwiftUI` 旋转木马效果

[English version](README.md) | 中文文档 [详细分析](https://juejin.cn/post/6898258968775245837)
[English Version](README.md) | [详细解析](https://juejin.cn/post/6898258968775245837)

<p align="center">
<img src='https://img.shields.io/badge/Swift-5.1-green?style=flat'>
Expand Down Expand Up @@ -43,7 +43,7 @@
也可以将 `ACarousel` 作为依赖添加项到你的 `Package.swift` 中:
```swift
dependencies: [
.package(url: "https://github.com/JWAutumn/ACarousel", from: "0.1.3")
.package(url: "https://github.com/JWAutumn/ACarousel", from: "0.2.0")
]
```

Expand Down Expand Up @@ -82,6 +82,23 @@ struct ContentView: View {
}
```

或者:

```swift
...
var body: some View {
ACarousel(roles, id: \.self) { name in
Image(name)
.resizable()
.scaledToFill()
.frame(height: 300)
.cornerRadius(30)
}
.frame(height: 300)
}
...
```

- 自定义参数:根据自身需求,你可以修改相应的参数来自定义显示样式。
```swift
/// ...
Expand Down
Loading

0 comments on commit 8a32251

Please sign in to comment.