         searchBar.text = currentSearch?.localizedDescription
     }
     
-    var searchSuggestionsHidden = true {
-        didSet {
-            searchSuggestionView.isHidden = searchSuggestionsHidden
-            if searchSuggestionsHidden {
-                navigationItem.setRightBarButton(segmentedControlBarButtonItem, animated: true)
-            } else {
-                navigationItem.setRightBarButton(closeBarButtonItem, animated: true)
-            }
-        }
-    }
-    
     // MARK: UISearchBarDelegate
     
     func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
         if let type = currentSearch?.type, type != .text {
             searchBar.text = nil
         }
-        searchSuggestionsHidden = false
+        viewMode = .search
         updateSearchSuggestions(withCompletions: [])
         deselectAllAnnotations()
     }

        segmentedControl = UISegmentedControl(items: [map, list])
        
        segmentedControl.selectedSegmentIndex = 0
        segmentedControl.addTarget(self, action: #selector(segmentedControlChanged), for: .valueChanged)
        segmentedControl.tintColor = UIColor.wmf_blueTint()
        segmentedControlBarButtonItem = UIBarButtonItem(customView: segmentedControl)
        navigationItem.rightBarButtonItem = segmentedControlBarButtonItem

        }
    }
    
    enum ViewMode {
        case map
        case list
        case search
    }
    
    var viewMode: ViewMode = .map {
        didSet {
            if oldValue == .search && viewMode != .search {
                navigationItem.setRightBarButton(segmentedControlBarButtonItem, animated: true)
            } else if oldValue != .search && viewMode == .search {
                navigationItem.setRightBarButton(closeBarButtonItem, animated: true)
            }
            switch viewMode {
            case .list:
                deselectAllAnnotations()
                updateDistanceFromUserOnVisibleCells()
                mapView.isHidden = true
                listView.isHidden = false
                searchSuggestionView.isHidden = true
            case .search:
                mapView.isHidden = true
                listView.isHidden = true
                searchSuggestionView.isHidden = false
            case .map:
                fallthrough
            default:
                mapView.isHidden = false
                listView.isHidden = true
                searchSuggestionView.isHidden = true
            }
            recenterOnUserLocationButton.isHidden = mapView.isHidden
            redoSearchButton.isHidden = mapView.isHidden
        }
    }
    
    func updateViewModeFromSegmentedControl() {
        switch segmentedControl.selectedSegmentIndex {
        case 0:
            viewMode = .map
        default:
            viewMode = .list
        }
    }
    
