1.0.0 • Published 5 years ago

react-native-session-timer-modal v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

Coverage Status Build Status Codacy Badge

React Native Session Timer Modal

A customizable session timer modal that times even when the app is on the background (not really, it uses timestamp to work around the iOS background limitation). It won't work with Expo since it makes use of react-native-background-timer which requires native library linking.

Demo

note: This demo has a backgroundTime of 0.07 minutes and a modalTime of 10 minutes.

GIF DEMO

Getting started

yarn add react-native-session-timer-modal

Automatic Linking

react-native link react-native-background-timer

note: This is linking the dependent library react-native-background-timer instead of this library.

Manual Linking

Follow this readme to manually link the react-native-background-timer library.

Usage

  1. Wrap your app with <SessionTimerModal /> in App.js (or wherever the root of your project is), and configure the props, make sure you checkout the props table below to custimze the appearance!

    ...
    import SessionTimerModal, { startSessionTimer, stopSessionTimer } from 'react-native-session-timer-modal';
    
    ...
    render() {
      ...
      return (
        <SessionTimerModal
          backgroundTime={9}
          modalTime={1}
          containerStyle={styles.container}
          title="Session Timer"
          titleStyle={styles.title}
          subtitle="Your session will be ending soon! Wanna stay in the app?"
          subtitleStyle={styles.subtitle}
          confirmButtonConfigs={{
            text: 'Oh yea'
          }}
          cancelButtonConfigs={{
            text: 'Log me out',
            textStyle: styles.cancelText
          }}
          onTimerEnd={() => Alert.alert('Timer End')}
        >
          <App />
        </SessionTimerModal>
      )
    }
    ...
  2. Call startSessionTimer() when your app finished logging the user in and when the refresh token call finised.

  3. Call stopSessionTimer() when the user logs out.

Props Definitions

<SessionTimerModal />

PropExplanationTypeDefault
backgroundTimeThe number of minutes that the modal will be counting on the background, specifically it is the time period between startSessionTimer is called and the counting modal shows up.number9
modalTimeThe number of minutes that the modal will be counting after the modal shows up.number1
titleTitle of the modal.string''
subtitleSubtitle of the modal.string''
containerStyleThe styles for the modal card.ViewStylenull
titleStyleThe styles for the title.TextStylenull
subtitleStyleThe styles for the subtitle.TextStylenull
countdownTextStyleThe styles for the countdown number.TextStylenull
buttonsContainerStyleThe styles for the the buttons row container.ViewStylenull
modalConfigsProps for the react-native-modal, pass them down as an object.ModalProps{}
cancelButtonConfigsThe configurations for cancel button, the left one.IButtonConfigs (see below for the definition of this){}
confirmButtonConfigsThe configurations for confirm button, the right one.IButtonConfigs (see below for the definition of this){}
onTimerEndThe callback function called when the modal counts to 0 seconds.functionnull

IButtonConfigs

PropExplanationTypeDefault
buttonStyleThe styles for the TouchableOpacity button.ViewStylenull
buttonViewStyleThe styles for the single View within TouchableOpacity button.ViewStylenull
textStyleThe styles for the button text.TextStylenull
textText of the button.string''
onPressCallback when the user taps the button, best place to call your refresh token or log out function depending on how you setup your cancel and confirm button.function() => null