import { Dimensions } from 'react-native' ; import { style } from './index' ; export let MainWidth = Dimensions . get ( 'window' ) . width ; export let MainHeight = Dimensions . get ( 'window' ) . height ; export enum xLocation { start = 'flex-start' , center = 'center' , end = 'flex-end' } export interface getLocationReturn { style : style ; isDown : boolean ; isStart : xLocation ; triangle : number ; } returns export function getLocation ( width , height , pageOffsetX , pageOffsetY , _W , _H ) { let isDown = false ; let isStart = xLocation . start ; let triangle = 0 ; let style = { } ; let halfWidth = width / 2 ; if ( pageOffsetY > MainHeight / 2 ) { isDown = true ; style . top = pageOffsetY - _H ; } else { isDown = false ; style . top = pageOffsetY + height ; } if ( pageOffsetX === ( MainWidth - width ) / 2 ) { isStart = xLocation . center ; style . left = ( MainWidth - _W ) / 2 ; } if ( MainWidth - width - pageOffsetX > pageOffsetX ) { isStart = xLocation . start ; style . left = pageOffsetX + halfWidth - 16 ; } if ( MainWidth - width - pageOffsetX < pageOffsetX ) { isStart = xLocation . end ; style . left = pageOffsetX - halfWidth + 16 ; } if ( _W + pageOffsetX >= MainWidth - 40 ) { style . width = MainWidth - 40 ; triangle = pageOffsetX + halfWidth - 20 - 10 - 6 ; style . left = 20 ; if ( pageOffsetY > MainHeight / 2 ) { style . top = pageOffsetY ; } } return { style , isDown , isStart , triangle , } ; }