Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #7698: Adds search back button animation (#7840)
Browse files Browse the repository at this point in the history
* For #7698: Adds search back button animation

* Refactor for searchController
  • Loading branch information
sblatz committed Jan 22, 2020
1 parent 2372ee6 commit 20396f7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DefaultSearchController(
}

override fun handleEditingCancelled() {
store.dispatch(SearchFragmentAction.UpdateEditingCanceled)
navController.navigateUp()
}

Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import android.view.ViewGroup
import android.view.ViewStub
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.core.view.marginStart
import androidx.fragment.app.Fragment
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.navigation.fragment.findNavController
import androidx.transition.TransitionInflater
import kotlinx.android.synthetic.main.fragment_search.*
Expand Down Expand Up @@ -111,7 +113,8 @@ class SearchFragment : Fragment(), UserInteractionHandler {
showBookmarkSuggestions = requireContext().settings().shouldShowBookmarkSuggestions,
session = session,
pastedText = pastedText,
searchAccessPoint = searchAccessPoint
searchAccessPoint = searchAccessPoint,
isAnimatingOut = false
)
)
}
Expand Down Expand Up @@ -199,7 +202,7 @@ class SearchFragment : Fragment(), UserInteractionHandler {
}

view.back_button.setOnClickListener {
findNavController().navigateUp()
searchInteractor.onEditingCanceled()
}

val stubListener = ViewStub.OnInflateListener { _, inflated ->
Expand Down Expand Up @@ -253,6 +256,7 @@ class SearchFragment : Fragment(), UserInteractionHandler {
updateSearchWithLabel(it)
updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url)
updateSearchSuggestionsHintVisibility(it)
updateBackButton(it)
}

startPostponedEnterTransition()
Expand Down Expand Up @@ -316,6 +320,13 @@ class SearchFragment : Fragment(), UserInteractionHandler {
clipboard_url.text = clipboardUrl
}

private fun updateBackButton(searchState: SearchFragmentState) {
if (searchState.isAnimatingOut) {
searchStore.dispatch(SearchFragmentAction.ConsumeEditingCancelled)
animateBackButtonAway()
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
Expand Down Expand Up @@ -352,6 +363,18 @@ class SearchFragment : Fragment(), UserInteractionHandler {
}
}

private fun animateBackButtonAway() {
val backButton = requireView().back_button
val xTranslation = with(backButton) {
-(width + marginStart + paddingStart).toFloat()
}

backButton
.animate()
.translationX(xTranslation)
.interpolator = FastOutSlowInInterpolator()
}

companion object {
private const val SHARED_TRANSITION_MS = 200L
private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ data class SearchFragmentState(
val showBookmarkSuggestions: Boolean,
val session: Session?,
val pastedText: String? = null,
val searchAccessPoint: Event.PerformedSearch.SearchAccessPoint?
val searchAccessPoint: Event.PerformedSearch.SearchAccessPoint?,
val isAnimatingOut: Boolean
) : State

/**
* Actions to dispatch through the `SearchStore` to modify `SearchState` through the reducer.
*/
sealed class SearchFragmentAction : Action {
object UpdateEditingCanceled : SearchFragmentAction()
object ConsumeEditingCancelled : SearchFragmentAction()
data class SearchShortcutEngineSelected(val engine: SearchEngine) : SearchFragmentAction()
data class SelectNewDefaultSearchEngine(val engine: SearchEngine) : SearchFragmentAction()
data class ShowSearchShortcutEnginePicker(val show: Boolean) : SearchFragmentAction()
Expand Down Expand Up @@ -91,5 +94,9 @@ private fun searchStateReducer(state: SearchFragmentState, action: SearchFragmen
)
is SearchFragmentAction.ShowSearchSuggestionsHint ->
state.copy(showSearchSuggestionsHint = action.show)
is SearchFragmentAction.UpdateEditingCanceled ->
state.copy(isAnimatingOut = true)
is SearchFragmentAction.ConsumeEditingCancelled ->
state.copy(isAnimatingOut = false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SearchFragmentStoreTest {
showHistorySuggestions = false,
showBookmarkSuggestions = false,
session = null,
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.NONE
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.NONE,
isAnimatingOut = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.verify
import io.mockk.mockkObject
import io.mockk.verify
import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.session.Session
Expand Down Expand Up @@ -85,7 +85,7 @@ class SearchInteractorTest {
@Test
fun onEditingCanceled() {
val navController: NavController = mockk(relaxed = true)
val store: SearchFragmentStore = mockk()
val store: SearchFragmentStore = mockk(relaxed = true)

every { store.state } returns mockk(relaxed = true)

Expand All @@ -99,6 +99,7 @@ class SearchInteractorTest {
interactor.onEditingCanceled()

verify {
store.dispatch(SearchFragmentAction.UpdateEditingCanceled)
navController.navigateUp()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.mozilla.fenix.detektrules
import io.gitlab.arturbosch.detekt.api.ConsoleReport
import io.gitlab.arturbosch.detekt.api.Detektion

class CustomRulesetConsoleReport: ConsoleReport() {
class CustomRulesetConsoleReport : ConsoleReport() {
override fun render(detektion: Detektion): String? {
return detektion.findings["mozilla-detekt-rules"]?.fold("") { output, finding ->
output + finding.locationAsString + ": " + finding.messageOrDescription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider

class CustomRulesetProvider: RuleSetProvider {
class CustomRulesetProvider : RuleSetProvider {
override val ruleSetId: String = "mozilla-detekt-rules"

override fun instance(config: Config): RuleSet = RuleSet(
Expand All @@ -17,6 +17,4 @@ class CustomRulesetProvider: RuleSetProvider {
MozillaBannedPropertyAccess(config)
)
)


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.psi.*

class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
class MozillaBannedPropertyAccess(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
"MozillaBannedPropertyAccess",
Severity.Defect,
Expand All @@ -27,7 +27,6 @@ class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
listOf<String>()
} else {
bannedPropertiesList.split(",")

}
}

Expand All @@ -44,7 +43,7 @@ class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
CodeSmell(
issue,
Entity.from(expression),
"Using ${possiblyBannedPropertyAccess} is not allowed because accessing property ${it} is against Mozilla policy. See 'mozilla-detekt-rules' stanza in 'config/detekt.yml' for more information.\n"
"Using $possiblyBannedPropertyAccess is not allowed because accessing property $it is against Mozilla policy. See 'mozilla-detekt-rules' stanza in 'config/detekt.yml' for more information.\n"
)
}.forEach { report(it) }
}
Expand Down

0 comments on commit 20396f7

Please sign in to comment.