import * as common from './pulltorefresh-common' ; export * from './pulltorefresh-common' ; declare const global ; const SwipeRefreshLayout_Namespace = useAndroidX ( ) ? androidx . swiperefreshlayout . widget : ( android . support . v4 as any ) . widget ; function useAndroidX ( ) { return global . androidx && androidx . swiperefreshlayout ; } @ NativeClass ( ) class CarouselFriendlySwipeRefreshLayout extends SwipeRefreshLayout_Namespace . SwipeRefreshLayout { private _touchSlop : number ; private _previousX : number ; public constructor ( context , attrs ) { super ( context , attrs ) ; this . _touchSlop = android . view . ViewConfiguration . get ( context ) . getScaledTouchSlop ( ) ; } public onInterceptTouchEvent ( event ) { switch ( event . getAction ( ) ) { case android . view . MotionEvent . ACTION_DOWN : { this . _previousX = android . view . MotionEvent . obtain ( event ) . getX ( ) ; break ; } case android . view . MotionEvent . ACTION_MOVE : { const eventX = event . getX ( ) ; const xDifference = Math . abs ( eventX - this . _previousX ) ; if ( xDifference > this . _touchSlop ) { return false ; } break ; } } return super . onInterceptTouchEvent ( event ) ; } } export class PullToRefresh extends common . PullToRefreshBase { private _androidViewId : number ; public nativeView : androidx . swiperefreshlayout . widget . SwipeRefreshLayout ; public createNativeView ( ) { const swipeRefreshLayout = new ( CarouselFriendlySwipeRefreshLayout as any ) ( this . _context ) ; if ( ! this . _androidViewId ) { this . _androidViewId = android . view . View . generateViewId ( ) ; } swipeRefreshLayout . setId ( this . _androidViewId ) ; if ( useAndroidX ( ) ) { const androidXListener = new androidx . swiperefreshlayout . widget . SwipeRefreshLayout . OnRefreshListener ( { onRefresh ( ) { const owner = this . owner . get ( ) ; if ( owner ) { owner . refreshing = true ; owner . notify ( { eventName : common . PullToRefreshBase . refreshEvent , object : owner , } ) ; } } , } ) ; swipeRefreshLayout . setOnRefreshListener ( androidXListener ) ; ( swipeRefreshLayout as any ) . refreshListener = androidXListener ; } else { const supportListener = new ( android . support . v4 as any ) . widget . SwipeRefreshLayout . OnRefreshListener ( { onRefresh ( v ) { const owner = this . owner . get ( ) ; if ( owner ) { owner . refreshing = true ; owner . notify ( { eventName : common . PullToRefreshBase . refreshEvent , object : owner , } ) ; } } , } ) ; swipeRefreshLayout . setOnRefreshListener ( supportListener ) ; ( swipeRefreshLayout as any ) . refreshListener = supportListener ; } return swipeRefreshLayout ; } public initNativeView ( ) { super . initNativeView ( ) ; const nativeView = this . nativeView as any ; nativeView . refreshListener . owner = new WeakRef ( this ) ; } public disposeNativeView ( ) { const nativeView = this . nativeView as any ; nativeView . refreshListener . owner = null ; super . disposeNativeView ( ) ; } [ common . refreshingProperty . getDefault ] ( ) { return false ; } [ common . refreshingProperty . setNative ] ( value ) { this . nativeView . setRefreshing ( value ) ; } [ common . indicatorColorProperty . setNative ] ( value ) { const color = value ? value . android : this . color ; this . nativeView . setColorSchemeColors ( [ color ] ) ; } [ common . indicatorColorStyleProperty . setNative ] ( value ) { if ( ( this as any ) . indicatorColor ) { return ; } const color = value ? value . android : this . color ; this . nativeView . setColorSchemeColors ( [ color ] ) ; } [ common . indicatorFillColorProperty . setNative ] ( value ) { const color = value ? value . android : this . backgroundColor ; this . nativeView . setProgressBackgroundColorSchemeColor ( color ) ; } [ common . indicatorFillColorStyleProperty . setNative ] ( value ) { if ( ( this as any ) . indicatorFillColor ) { return ; } const color = value ? value . android : this . backgroundColor ; this . nativeView . setProgressBackgroundColorSchemeColor ( color ) ; } }