Skip to content

Instantly share code, notes, and snippets.

Nick Butcher nickbutcher

Block or report user

Report or block nickbutcher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View animated_visibility.kt
/* 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
view.visibility = View.VISIBLE
val spring = view.spring(SpringAnimation.ALPHA)
(view.getTag(R.id.tag_pending_end_listener) as?
DynamicAnimation.OnAnimationEndListener)?.let {
View spring_binding.diff
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
- val anim = view.animate().alpha(targetAlpha)
+ val spring = view.spring(SpringAnimation.ALPHA)
+ spring.animateToFinalPosition(targetAlpha)
View spring_ext_fun.kt
/* 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)
View view_property_animator.diff
/* 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 }
+ }
View continuity.diff
/* 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()
View naive_animated_binding.kt
/* 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()
View static_binding.kt
/* 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)
View lazy.diff
/* 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
View ShowbizView.kt
/*
* 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
View vector_LoadCompatDrawable.kt
/* 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
You can’t perform that action at this time.