This file contains hidden or 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
_... | |
o_.-"` `\ | |
.--. _ `'-._.-'""-; _ | |
.' \`_\_ {_.-a"a-} _ / \ | |
_/ .-' '. {c-._o_.){\|` | |
This file contains hidden or 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
/** | |
* Navigates only if this is safely possible; when this Fragment is still the current destination. | |
*/ | |
fun Fragment.navigateSafe( | |
@IdRes resId: Int, | |
args: Bundle? = null, | |
navOptions: NavOptions? = null, | |
navigatorExtras: Navigator.Extras? = null | |
) { | |
if (mayNavigate()) findNavController().navigate( |
This file contains hidden or 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
/** | |
* Returns true if the navigation controller is still pointing at 'this' fragment, or false if it already navigated away. | |
*/ | |
fun Fragment.mayNavigate(): Boolean { | |
val navController = findNavController() | |
val destinationIdInNavController = navController.currentDestination?.id | |
// add tag_navigation_destination_id to your ids.xml so that it's unique: | |
val destinationIdOfThisFragment = view?.getTag(R.id.tag_navigation_destination_id) ?: destinationIdInNavController |
This file contains hidden or 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
class ApiMainHeadersProvider { | |
/** | |
* Public headers for calls that do not need an authenticated user. | |
*/ | |
fun getPublicHeaders(): PublicHeaders = | |
PublicHeaders().apply { | |
putAll(getDefaultHeaders()) | |
} |
This file contains hidden or 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
/** | |
* Holds and manages ViewBinding inside a Fragment. | |
*/ | |
interface ViewBindingHolder<T : ViewBinding> { | |
val binding: T? | |
/** | |
* Saves the binding for cleanup on onDestroy, calls the specified function [onBound] with `this` value | |
* as its receiver and returns the bound view root. |
This file contains hidden or 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
class ExampleFragment : Fragment(), ViewBindingHolder<FragmentExampleBinding> by ViewBindingHolderImpl() { | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? = initBinding(FragmentExampleBinding.inflate(layoutInflater), this) { | |
// do your onCreateView logic here, where 'this' is the binding object. | |
textTitle.text = "Clean ViewBinding and Lifecycle handling" |
This file contains hidden or 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
import android.graphics.Rect | |
import android.support.test.espresso.Espresso.onView | |
import android.support.test.espresso.PerformException | |
import android.support.test.espresso.UiController | |
import android.support.test.espresso.ViewAction | |
import android.support.test.espresso.matcher.ViewMatchers.* | |
import android.support.test.espresso.util.HumanReadables | |
import android.support.test.espresso.util.TreeIterables | |
import android.view.View | |
import android.view.ViewGroup |
This file contains hidden or 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
import {Platform} from 'react-native'; | |
const getPlatformTestId = (id: string) => | |
Platform.OS === 'ios' ? {testID: id} : {accessible: true, accessibilityLabel: id}; | |
/** | |
* Adds a testID to the views on Android and iOS in their specific ways. On Android, | |
* this will result in a ContentDescription on Debug builds (and no changes on live builds). | |
*/ | |
const setTestID = (id : string) => |
This file contains hidden or 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
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.RectF; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/** | |
* Shows progress on a circle chart. |