Skip to content

Commit c74d4c8

Browse files
committed
refactor and fixed ui for Profile, Event, Chat Views
1 parent 19e7b5e commit c74d4c8

14 files changed

+221
-149
lines changed

Addame.xcodeproj/project.pbxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
"$(inherited)",
316316
"@executable_path/Frameworks",
317317
);
318-
MARKETING_VERSION = 1.2.2;
318+
MARKETING_VERSION = 1.2.3;
319319
PRODUCT_BUNDLE_IDENTIFIER = com.addame.AddaMeIOS;
320320
PRODUCT_NAME = "$(TARGET_NAME)";
321321
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -463,7 +463,7 @@
463463
"$(inherited)",
464464
"@executable_path/Frameworks",
465465
);
466-
MARKETING_VERSION = 1.2.2;
466+
MARKETING_VERSION = 1.2.3;
467467
PRODUCT_BUNDLE_IDENTIFIER = com.addame.AddaMeIOS;
468468
PRODUCT_NAME = "$(TARGET_NAME)";
469469
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -491,7 +491,7 @@
491491
"$(inherited)",
492492
"@executable_path/Frameworks",
493493
);
494-
MARKETING_VERSION = 1.2.2;
494+
MARKETING_VERSION = 1.2.3;
495495
PRODUCT_BUNDLE_IDENTIFIER = com.addame.AddaMeIOS;
496496
PRODUCT_NAME = "$(TARGET_NAME)";
497497
PROVISIONING_PROFILE_SPECIFIER = "";

AddameSPM/Sources/AppFeature/AppView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SharedModels
2020

2121
public enum AppState: Equatable {
2222
case login(LoginState)
23-
case tabs(TabsState)
23+
case tabs(TabsViewState)
2424

2525
public init() { self = .login(.init()) }
2626
}

AddameSPM/Sources/ChatView/ChatListView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ChatListView: View {
2828
viewStore.send(.fetchMoreMessageIfNeeded(currentItem: messageViewStore.state))
2929
}
3030
.scaleEffect(x: 1, y: -1, anchor: .center)
31-
.hideRowSeparator(background: .white)
31+
.listRowSeparatorHidden()
3232
}
3333
}
3434
}

AddameSPM/Sources/ChatView/ChatView.swift

+7-41
Original file line numberDiff line numberDiff line change
@@ -110,49 +110,15 @@ public struct ChatView: View {
110110
// }
111111

112112
extension View {
113-
/// 隐藏 List 中的 分割线
114-
func hideRowSeparator(insets: EdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0),
115-
background: Color = .white) -> some View {
116-
modifier(HideRowSeparatorModifier(insets: insets, background: background))
117-
}
118-
}
119-
120-
struct HideRowSeparatorModifier: ViewModifier {
121-
122-
static let defaultListRowHeight: CGFloat = 44
123113

124-
var insets: EdgeInsets
125-
var background: Color
126-
127-
init(insets: EdgeInsets, background: Color) {
128-
self.insets = insets
129-
130-
var alpha: CGFloat = 0
131-
if #available(iOS 14.0, *) {
132-
UIColor(background).getWhite(nil, alpha: &alpha)
133-
assert(alpha == 1, "Setting background to a non-opaque color will result in separators remaining visible.")
114+
@ViewBuilder func listRowSeparatorHidden() -> some View {
115+
if #available(iOS 15.0, *) {
116+
self.listRowSeparator(.hidden)
117+
} else { // ios 14
118+
self.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
119+
.listRowInsets(EdgeInsets(top: -1, leading: 16, bottom: -1, trailing: 16))
120+
.background(Color(.systemBackground))
134121
}
135-
self.background = background
136122
}
137123

138-
func body(content: Content) -> some View {
139-
content
140-
.padding(insets)
141-
.frame(minWidth: 0, maxWidth: .infinity, minHeight: Self.defaultListRowHeight)
142-
.listRowInsets(EdgeInsets())
143-
.overlay(
144-
VStack {
145-
HStack {}
146-
.frame(maxWidth: .infinity)
147-
.frame(height: 1)
148-
.background(background)
149-
Spacer()
150-
HStack {}
151-
.frame(maxWidth: .infinity)
152-
.frame(height: 1)
153-
.background(background)
154-
}
155-
.padding(.top, -1)
156-
)
157-
}
158124
}

AddameSPM/Sources/ConversationsView/ConversationsView.swift

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public struct ConversationsView: View {
8989
.redacted(reason: viewStore.isLoadingPage ? .placeholder : [])
9090
}
9191
}
92+
9293
.navigationTitle("Chats")
9394
.toolbar {
9495
ToolbarItem(placement: .navigationBarTrailing) {
@@ -110,6 +111,10 @@ public struct ConversationsView: View {
110111
.alert(self.store.scope(state: { $0.alert }), dismiss: ConversationsAction.alertDismissed)
111112
}
112113
.debug("ConversationView")
114+
.onAppear {
115+
ViewStore(store.stateless).send(.onAppear)
116+
}
117+
.navigationViewStyle(StackNavigationViewStyle())
113118
.sheet(
114119
store.scope(state: \.contactsState, action: ConversationsAction.contacts),
115120
state: replayNonNil(),

AddameSPM/Sources/EventView/EventView.swift

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public struct EventView: View {
144144
color: viewStore.state.isLocationAuthorized ? Color.green : Color.red, radius: 20, y: 5)
145145
}
146146
}
147+
.navigationViewStyle(StackNavigationViewStyle())
147148
.navigationBarTitleDisplayMode(.automatic)
148149
.toolbar {
149150
ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
@@ -152,6 +153,9 @@ public struct EventView: View {
152153
}
153154
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
154155
}
156+
.onAppear {
157+
ViewStore(store.stateless).send(.onAppear)
158+
}
155159
.sheet(
156160
store.scope(state: \.eventDetailsState, action: EventsAction.eventDetails),
157161
state: replayNonNil(),

AddameSPM/Sources/EventView/EventsAction.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum EventsAction: Equatable {
3838
case currentLocationButtonTapped
3939
case locationManager(LocationManager.Action)
4040
case eventsResponse(Result<EventResponse, HTTPRequest.HRError>)
41-
case eventCoordinate(Result<CLPlacemark, Never>)
41+
case eventPlacemarkResponse(Result<CLPlacemark, Never>)
4242
case eventTapped(EventResponse.Item)
4343

4444
case popupSettings

AddameSPM/Sources/EventView/EventsEnvironment.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct EventsEnvironment {
3939
self.userDefaults = userDefaults
4040
}
4141

42-
func getCoordinate(_ location: Location) -> Effect<CLPlacemark, Never> {
42+
func getPlacemark(_ location: Location) -> Effect<CLPlacemark, Never> {
4343
return Effect<CLPlacemark, Never>.future { callback in
4444
let address = CLGeocoder()
4545
address.reverseGeocodeLocation(

AddameSPM/Sources/EventView/EventsReducer.swift

+13-10
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
8080
}
8181

8282
var fetchEvents: Effect<EventsAction, Never> {
83-
guard state.isConnected, let location = state.location else { return .none }
84-
state.location = location
83+
guard state.isConnected && state.canLoadMorePages,
84+
let location = state.location
85+
else {
86+
return .none
87+
}
8588

86-
guard state.canLoadMorePages else { return .none }
89+
state.location = location
8790

8891
let getDistanceType = environment.userDefaults.integerForKey("typee")
8992
let maxDistance = getDistanceType == 0 ? (250 * 1000) : (250 / 1.609) * 1609
@@ -122,11 +125,11 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
122125
.map(EventsAction.eventsResponse)
123126
}
124127

125-
func getLocation(_ location: Location) -> Effect<EventsAction, Never> {
126-
return environment.getCoordinate(location)
128+
func getPlacemark(_ location: Location) -> Effect<EventsAction, Never> {
129+
return environment.getPlacemark(location)
127130
.receive(on: environment.mainQueue)
128131
.catchToEffect()
129-
.map(EventsAction.eventCoordinate)
132+
.map(EventsAction.eventPlacemarkResponse)
130133
}
131134

132135
func presentChatView() -> Effect<EventsAction, Never> {
@@ -139,6 +142,7 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
139142

140143
switch action {
141144
case .onAppear:
145+
142146
let status = environment.locationManager.authorizationStatus()
143147
if status == .authorizedAlways || status == .authorizedWhenInUse {
144148
return fetchEvents
@@ -205,7 +209,7 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
205209
case let .addressResponse(.success(address)):
206210
return .none
207211

208-
case let .eventCoordinate(.success(placemark)):
212+
case let .eventPlacemarkResponse(.success(placemark)):
209213
let formatter = CNPostalAddressFormatter()
210214
guard let postalAddress = placemark.postalAddress else {
211215
// handle error here
@@ -218,14 +222,13 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
218222
return .none
219223

220224
case let .locationManager(.didUpdateLocations(locations)):
221-
225+
state.isLoadingPage = true
222226
guard state.isConnected, let location = locations.first else { return .none }
223227
state.location = location
224228

225-
state.isLoadingPage = true
226229
return .merge(
227230
fetchEvents,
228-
getLocation(location)
231+
getPlacemark(location)
229232
)
230233

231234
case .locationManager:

AddameSPM/Sources/ProfileView/ProfileView.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extension ProfileView {
2626
public var isLoadingPage = false
2727
public var canLoadMorePages = true
2828
public var currentPage = 1
29+
public var index = 0
2930
public var settingsState: SettingsState?
3031
public var imagePickerState: ImagePickerState?
3132
public var imageURLs: [String] = []
@@ -66,7 +67,12 @@ public struct ProfileView: View {
6667

6768
@ViewBuilder
6869
public var body: some View {
69-
WithViewStore(self.store.scope(state: { $0.view }, action: ProfileAction.view)) { viewStore in
70+
WithViewStore(
71+
self.store.scope(
72+
state: { $0.view },
73+
action: ProfileAction.view
74+
)
75+
) { viewStore in
7076

7177
ScrollView(.vertical) {
7278

@@ -76,6 +82,7 @@ public struct ProfileView: View {
7682
maxIndex: viewStore.state.imageURLs.count - 1
7783
) {
7884
ForEach(viewStore.state.imageURLs, id: \.self) { url in
85+
7986
AsyncImage(
8087
urlString: url,
8188
placeholder: {
@@ -142,6 +149,10 @@ public struct ProfileView: View {
142149
}
143150
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
144151
}
152+
.onAppear {
153+
ViewStore(store.stateless).send(.onAppear)
154+
}
155+
.navigationViewStyle(StackNavigationViewStyle())
145156
.sheet(
146157
store.scope(
147158
state: \.imagePickerState,

AddameSPM/Sources/TabsView/TabsAction.swift

+17
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,20 @@ public enum TabsAction: Equatable {
2424
case receivedSocketMessage(Result<WebSocketClient.Message, NSError>)
2525
case sendResponse(NSError?)
2626
}
27+
28+
extension TabsAction {
29+
static func view(_ localAction: TabsView.ViewAction) -> Self {
30+
switch localAction {
31+
case .onAppear:
32+
return .onAppear
33+
case let .didSelectTab(tabs):
34+
return .didSelectTab(tabs)
35+
case let .event(action):
36+
return .event(action)
37+
case let .conversation(action):
38+
return .conversation(action)
39+
case let .profile(action):
40+
return .profile(action)
41+
}
42+
}
43+
}

AddameSPM/Sources/TabsView/TabsReducer.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import KeychainService
1414
import ProfileView
1515
import SharedModels
1616

17-
public let tabsReducer = Reducer<TabsState, TabsAction, TabsEnvironment>.combine(
17+
public let tabsReducer = Reducer<
18+
TabsViewState,
19+
TabsAction,
20+
TabsEnvironment
21+
>.combine(
1822
eventReducer.pullback(
1923
state: \.event,
2024
action: /TabsAction.event,

AddameSPM/Sources/TabsView/TabsState.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct TabsState: Equatable {
3434
public var profile: ProfileState
3535
}
3636

37-
struct TabsViewState: Equatable {
37+
public struct TabsViewState: Equatable {
3838
public init(
3939
selectedTab: Tabs, event: EventsState, conversations: ConversationsState, profile: ProfileState
4040
) {
@@ -49,3 +49,14 @@ struct TabsViewState: Equatable {
4949
public var conversations: ConversationsState
5050
public var profile: ProfileState
5151
}
52+
53+
extension TabsViewState {
54+
public var view: TabsView.ViewState {
55+
TabsView.ViewState(
56+
selectedTab: selectedTab,
57+
event: event,
58+
conversations: conversations,
59+
profile: profile
60+
)
61+
}
62+
}

0 commit comments

Comments
 (0)