Compare commits
5 Commits
master
...
research/l
Author | SHA1 | Date |
---|---|---|
![]() |
44a50e5f76 | |
![]() |
42d7b3e5c9 | |
![]() |
920e25f08b | |
![]() |
1107cef572 | |
![]() |
5297cf65dd |
|
@ -536,9 +536,9 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Example.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Example.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
|
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 4.0.0;
|
CURRENT_PROJECT_VERSION = 4.0.0;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = 6F2G55XL63;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
INFOPLIST_FILE = iOS/Info.plist;
|
INFOPLIST_FILE = iOS/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
||||||
|
@ -566,9 +566,9 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Example.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Example.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
|
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 4.0.0;
|
CURRENT_PROJECT_VERSION = 4.0.0;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = 6F2G55XL63;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
INFOPLIST_FILE = iOS/Info.plist;
|
INFOPLIST_FILE = iOS/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
|
||||||
|
|
|
@ -17,7 +17,7 @@ private struct PageItem: Identifiable {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TwitterView: View {
|
struct TwitterView: View {
|
||||||
@State var selection = 4
|
@State var selection = 1
|
||||||
@State var toggle = true
|
@State var toggle = true
|
||||||
@State var swipeGestureEnabled = true
|
@State var swipeGestureEnabled = true
|
||||||
|
|
||||||
|
|
|
@ -524,11 +524,11 @@
|
||||||
28F828921C494B2C00330CF4 /* Debug */ = {
|
28F828921C494B2C00330CF4 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_IDENTITY = "";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 4.0.0;
|
CURRENT_PROJECT_VERSION = 4.0.0;
|
||||||
DEFINES_MODULE = YES;
|
DEFINES_MODULE = YES;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = 6F2G55XL63;
|
||||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||||
DYLIB_CURRENT_VERSION = 1;
|
DYLIB_CURRENT_VERSION = 1;
|
||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||||
|
@ -556,11 +556,11 @@
|
||||||
28F828931C494B2C00330CF4 /* Release */ = {
|
28F828931C494B2C00330CF4 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_IDENTITY = "";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 4.0.0;
|
CURRENT_PROJECT_VERSION = 4.0.0;
|
||||||
DEFINES_MODULE = YES;
|
DEFINES_MODULE = YES;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = 6F2G55XL63;
|
||||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||||
DYLIB_CURRENT_VERSION = 1;
|
DYLIB_CURRENT_VERSION = 1;
|
||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||||
|
|
|
@ -89,7 +89,84 @@ private struct WrapperPagerTabStripView<SelectionType, Content>: View where Sele
|
||||||
self._selection = selection
|
self._selection = selection
|
||||||
self.content = content()
|
self.content = content()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor public var body: some View {
|
||||||
|
GeometryReader { geometryProxy in
|
||||||
|
TabView(selection: $selection) {
|
||||||
|
content
|
||||||
|
.overlay(
|
||||||
|
GeometryReader { geo in
|
||||||
|
Color.clear
|
||||||
|
.preference(key: ScrollViewOffsetPreferenceKey.self, value: geo.frame(in: .named("PagerView")).minX)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.onPreferenceChange(ScrollViewOffsetPreferenceKey.self, perform: { offset in
|
||||||
|
print("Debug -> selection: \(selection), offset: \(offset)")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.tabViewStyle(PageTabViewStyle.page(indexDisplayMode: .never))
|
||||||
|
.coordinateSpace(name: "PagerView")
|
||||||
|
.gesture(swipeGestureEnabled && swipeOn ?
|
||||||
|
DragGesture(minimumDistance: 25).onChanged { value in
|
||||||
|
swipeOn = !(edgeSwipeGestureDisabled.contains(.left) &&
|
||||||
|
(selection == pagerSettings.itemsOrderedByIndex.first && value.translation.width > 0) ||
|
||||||
|
edgeSwipeGestureDisabled.contains(.right) &&
|
||||||
|
(selection == pagerSettings.itemsOrderedByIndex.last && value.translation.width < 0))
|
||||||
|
}.updating($translation) { value, state, _ in
|
||||||
|
if selection == pagerSettings.itemsOrderedByIndex.first && value.translation.width > 0 {
|
||||||
|
let normTrans = value.translation.width / (geometryProxy.size.width + 50)
|
||||||
|
let logValue = log(1 + normTrans)
|
||||||
|
state = geometryProxy.size.width/1.5 * logValue
|
||||||
|
} else if selection == pagerSettings.itemsOrderedByIndex.last && value.translation.width < 0 {
|
||||||
|
let normTrans = -value.translation.width / (geometryProxy.size.width + 50)
|
||||||
|
let logValue = log(1 + normTrans)
|
||||||
|
state = -geometryProxy.size.width / 1.5 * logValue
|
||||||
|
} else {
|
||||||
|
state = value.translation.width
|
||||||
|
}
|
||||||
|
}.onEnded { value in
|
||||||
|
let offset = value.predictedEndTranslation.width / geometryProxy.size.width
|
||||||
|
let selectionIndex = pagerSettings.indexOf(tag: selection) ?? 0
|
||||||
|
let newPredictedIndex = (CGFloat(selectionIndex) - offset).rounded()
|
||||||
|
let newIndex = min(max(Int(newPredictedIndex), 0), pagerSettings.items.count - 1)
|
||||||
|
if newIndex > selectionIndex {
|
||||||
|
selection = pagerSettings.nextSelection(for: selection)
|
||||||
|
} else if newIndex < selectionIndex {
|
||||||
|
selection = pagerSettings.previousSelection(for: selection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: nil)
|
||||||
|
.onAppear {
|
||||||
|
let frame = geometryProxy.frame(in: .local)
|
||||||
|
pagerSettings.width = frame.width
|
||||||
|
if let index = pagerSettings.indexOf(tag: selection) {
|
||||||
|
pagerSettings.contentOffset = -CGFloat(index) * frame.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: pagerSettings.itemsOrderedByIndex) { _ in
|
||||||
|
pagerSettings.contentOffset = -(CGFloat(pagerSettings.indexOf(tag: selection) ?? 0) * geometryProxy.size.width)
|
||||||
|
}
|
||||||
|
.onChange(of: geometryProxy.frame(in: .local)) { geometry in
|
||||||
|
pagerSettings.width = geometry.width
|
||||||
|
if let index = pagerSettings.indexOf(tag: selection) {
|
||||||
|
pagerSettings.contentOffset = -(CGFloat(index)) * geometry.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: selection) { newSelection in
|
||||||
|
pagerSettings.contentOffset = -(CGFloat(pagerSettings.indexOf(tag: newSelection) ?? 0) * geometryProxy.size.width)
|
||||||
|
swipeOn = true
|
||||||
|
}
|
||||||
|
.onChange(of: translation) { _ in
|
||||||
|
pagerSettings.contentOffset = translation - (CGFloat(pagerSettings.indexOf(tag: selection) ?? 0) * geometryProxy.size.width)
|
||||||
|
swipeOn = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.modifier(NavBarModifier(selection: $selection))
|
||||||
|
.environmentObject(pagerSettings)
|
||||||
|
.clipped()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@MainActor public var body: some View {
|
@MainActor public var body: some View {
|
||||||
GeometryReader { geometryProxy in
|
GeometryReader { geometryProxy in
|
||||||
LazyHStack(spacing: 0) {
|
LazyHStack(spacing: 0) {
|
||||||
|
@ -160,5 +237,14 @@ private struct WrapperPagerTabStripView<SelectionType, Content>: View where Sele
|
||||||
.environmentObject(pagerSettings)
|
.environmentObject(pagerSettings)
|
||||||
.clipped()
|
.clipped()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate struct ScrollViewOffsetPreferenceKey: PreferenceKey {
|
||||||
|
|
||||||
|
static var defaultValue: CGFloat = 0
|
||||||
|
|
||||||
|
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
|
||||||
|
value = nextValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue