@@ -175,6 +175,8 @@ final class HomeViewController: UIViewController {
175
175
176
176
private var storeInformationViewController : StoreInformationViewController ?
177
177
178
+ private let dismissObserver = PublishRelay < Void > ( )
179
+
178
180
private let viewModel : HomeViewModel
179
181
180
182
init ( viewModel: HomeViewModel ) {
@@ -210,14 +212,13 @@ private extension HomeViewController {
210
212
self . setMarker ( marker: Marker ( certificationType: filteredStore. type, position: location) , tag: UInt ( $0. id) )
211
213
}
212
214
}
213
- markerCancel ( )
215
+ storeInformationViewController ? . dismiss ( animated : true )
214
216
}
215
217
. disposed ( by: disposeBag)
216
218
217
219
viewModel. getStoreInformationOutput
218
220
. bind { [ weak self] store in
219
221
guard let self = self else { return }
220
- markerClicked ( )
221
222
presentStoreView ( )
222
223
storeInformationViewController? . setUIContents ( store: store)
223
224
}
@@ -262,56 +263,71 @@ private extension HomeViewController {
262
263
263
264
func markerTouchHandler( marker: Marker ) {
264
265
marker. touchHandler = { [ weak self] ( _: NMFOverlay ) -> Bool in
265
- guard let self = self else { return true }
266
- markerCancel ( )
267
- if clickedMarker != marker {
268
- clickedMarker? . isSelected = false
269
- }
270
- marker. isSelected. toggle ( )
271
- if marker. isSelected {
272
- viewModel. action ( input: . markerTapped( tag: marker. tag) )
266
+ if let clickedMarker = self ? . clickedMarker {
267
+ if clickedMarker == marker { return true }
268
+ if clickedMarker. isSelected {
269
+ self ? . storeInformationViewController? . dismiss ( animated: true ) { [ weak self] in
270
+ self ? . markerSelected ( marker: marker)
271
+ }
272
+ } else {
273
+ self ? . markerSelected ( marker: marker)
274
+ }
275
+ } else {
276
+ self ? . markerSelected ( marker: marker)
273
277
}
274
- clickedMarker = marker
275
278
276
279
return true
277
280
}
278
281
}
279
282
280
- func markerClicked( ) {
281
- locationBottomConstraint. constant = - 240
282
- refreshBottomConstraint. constant = - 240
283
- UIView . animate ( withDuration: 0.3 ) {
284
- self . view. layoutIfNeeded ( )
283
+ func markerSelected( marker: Marker ) {
284
+ marker. isSelected. toggle ( )
285
+ if marker. isSelected {
286
+ viewModel. action ( input: . markerTapped( tag: marker. tag) )
285
287
}
288
+ clickedMarker = marker
286
289
}
287
290
288
- func markerCancel( ) {
289
- locationBottomConstraint. constant = - 16
290
- refreshBottomConstraint. constant = - 17
291
+ func markerClicked( height: CGFloat ) {
292
+ mapView. mapView. logoMargin = UIEdgeInsets ( top: 0 , left: 0 , bottom: height, right: 0 )
293
+ locationBottomConstraint. constant = - height
294
+ refreshBottomConstraint. constant = - height
291
295
UIView . animate ( withDuration: 0.3 ) {
292
296
self . view. layoutIfNeeded ( )
293
297
}
294
- storeInformationViewController? . dismiss ( animated: true )
295
298
}
296
299
297
300
func presentStoreView( ) {
298
301
let storeViewModel = StoreInformationViewModelImpl (
299
302
getOpenClosedUseCase: GetOpenClosedUseCaseImpl ( ) ,
300
303
fetchImageUseCase: FetchImageUseCaseImpl ( repository: ImageRepositoryImpl ( ) )
301
304
)
302
- storeInformationViewController = StoreInformationViewController ( viewModel: storeViewModel)
305
+ let contentHeightObserver = PublishRelay < CGFloat > ( )
306
+ storeInformationViewController = StoreInformationViewController (
307
+ viewModel: storeViewModel,
308
+ contentHeightObserver: contentHeightObserver,
309
+ dismissObserver: dismissObserver
310
+ )
303
311
storeInformationViewController? . transitioningDelegate = self
304
-
312
+
305
313
if let viewController = storeInformationViewController {
306
- if let sheet = viewController. sheetPresentationController {
307
- let detentIdentifier = UISheetPresentationController . Detent. Identifier ( " detent " )
308
- let detent = UISheetPresentationController . Detent. custom ( identifier: detentIdentifier) { _ in
309
- return 224
314
+ contentHeightObserver
315
+ . bind { [ weak self] contentHeight in
316
+ guard let self = self else { return }
317
+ let bottomSafeArea : CGFloat = 34
318
+ let height = contentHeight - bottomSafeArea
319
+ if let sheet = viewController. sheetPresentationController {
320
+ let detentIdentifier = UISheetPresentationController . Detent. Identifier ( " detent " )
321
+ let detent = UISheetPresentationController . Detent. custom ( identifier: detentIdentifier) { _ in
322
+ return height
323
+ }
324
+ sheet. detents = [ detent]
325
+ sheet. largestUndimmedDetentIdentifier = detentIdentifier
326
+ sheet. preferredCornerRadius = 15
327
+ }
328
+ markerClicked ( height: contentHeight - bottomSafeArea + 16 )
310
329
}
311
- sheet. detents = [ detent]
312
- sheet. largestUndimmedDetentIdentifier = detentIdentifier
313
- sheet. preferredCornerRadius = 15
314
- }
330
+ . disposed ( by: disposeBag)
315
331
present ( viewController, animated: true )
316
332
}
317
333
}
@@ -438,21 +454,26 @@ extension HomeViewController: NMFMapViewCameraDelegate {
438
454
extension HomeViewController : NMFMapViewTouchDelegate {
439
455
440
456
func mapView( _ mapView: NMFMapView , didTapMap latlng: NMGLatLng , point: CGPoint ) {
441
- clickedMarker? . isSelected = false
442
- markerCancel ( )
457
+ storeInformationViewController? . dismiss ( animated: true )
443
458
}
444
459
445
460
}
446
461
447
462
extension HomeViewController : UIViewControllerTransitioningDelegate {
448
463
449
464
func animationController( forDismissed dismissed: UIViewController ) -> UIViewControllerAnimatedTransitioning ? {
450
- clickedMarker? . isSelected = false
451
- locationBottomConstraint. constant = - 16
452
- refreshBottomConstraint. constant = - 17
453
- UIView . animate ( withDuration: 0.3 ) {
454
- self . view. layoutIfNeeded ( )
455
- }
465
+ dismissObserver
466
+ . bind { [ weak self] in
467
+ guard let self = self else { return }
468
+ clickedMarker? . isSelected = false
469
+ mapView. mapView. logoMargin = UIEdgeInsets ( top: 0 , left: 0 , bottom: 0 , right: 0 )
470
+ locationBottomConstraint. constant = - 16
471
+ refreshBottomConstraint. constant = - 17
472
+ UIView . animate ( withDuration: 0.3 ) {
473
+ self . view. layoutIfNeeded ( )
474
+ }
475
+ }
476
+ . disposed ( by: disposeBag)
456
477
457
478
return nil
458
479
}
0 commit comments