This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
fun View.spring( | |
property: ViewProperty | |
): SpringAnimation { | |
val key = getKey(property) | |
var springAnim = getTag(key) as? SpringAnimation? | |
if (springAnim == null) { | |
springAnim = SpringAnimation(this, property) | |
setTag(key, springAnim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
- val anim = ObjectAnimator.ofFloat(view, View.ALPHA, targetAlpha) | |
- if (!visible) { | |
- anim.doOnEnd { view.visibility = View.GONE } | |
- } | |
+ val anim = view.animate().alpha(targetAlpha) | |
+ if (!visible) { | |
+ anim.withEndAction { view.visibility = View.GONE } | |
+ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
- ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f).start() | |
+ ObjectAnimator.ofFloat(view, View.ALPHA, 1f).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
fun animateVisibility(view: View, visible: Boolean) { | |
view.visibility = View.VISIBLE | |
if (visible) { | |
ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f).start() | |
} else { | |
ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f).apply { | |
doOnEnd { view.visibility = View.GONE } | |
}.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
data class LoginUiModel( | |
val submitEnabled: Boolean, | |
val loginInProgress: Boolean | |
) | |
… | |
setVisibility(login, !uiModel.loginInProgress) | |
setVisibility(progress, uiModel.loginInProgress) | |
… |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
fun animateVisibility(view: View, visible: Boolean) { | |
+ val targetAlpha = if (visible) 1f else 0f | |
+ if (view.alpha == targetAlpha) return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2018 Google Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | |
* except in compliance with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the | |
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2018 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
val progressBar = findViewById<ProgressBar>(R.id.loading) | |
val drawable = AppCompatResources.getDrawable(context, R.drawable.loading_indeterminate) | |
progressBar.indeterminateDrawable = drawable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2018 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
<animated-selector ...> | |
<item android:state_foo="true" android:drawable="@drawable/some_vector" /> | |
<item android:drawable="@drawable/some_other_vector" /> | |
<!-- no transitions specified --> | |
</animated-selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2018 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
<layout ...> | |
<data> | |
<import type="your.package.R" alias="R" /> | |
... | |
</data> | |
<ProgressBar ... | |
app:indeterminateDrawableCompat="@{R.drawable.foo}" /> |