npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-toaster

v1.2.2

Published

Simple top-pop toast feedback messages for React Native

Downloads

3,139

Readme

react-native-toaster dependencies Status

Simple top-pop toast feedback messages for React Native.

demo

Example

import React, { Component } from 'react'
import { View } from 'react-native'
import Toaster, { ToastStyles } from 'react-native-toaster'

class App extends Component {
  constructor (props) {
    super(props)
    this.state = { message: null }

    const messages = [
      { text: 'FYI' },
      { text: 'Hooray!', styles: ToastStyles.success },
      { text: 'Eek', styles: ToastStyles.warning },
      { text: 'Oh noe!', styles: ToastStyles.error }
    ]

    // Send each message 1 second apart
    messages.forEach((message, i) => {
      setTimeout(() => this.setState({ message }), i * 1000)
    })
  }

  render () {
    return (
      <View>
        <Toaster message={this.state.message} />
      </View>
    )
  }
}

Properties

| Prop | Default | Type | Description | | :------------ |:---------------:| :---------------:| :-----| | message | - | object / array | The current toast message to display (see below). Multiple messages are shown one at a time after each other. | | onShow | null | func | Callback called when a message is shown, passed the message as the first parameter | | onHide | null | func | Callback called when a message is hidden, passed the message as the first parameter | | onPress | null | func | Callback called when the user press a message, passed the message as the first parameter |

message

| Prop | Default | Type | Description | | :------------ |:---------------:| :---------------:| :-----| | text | - | string / node | Text message to display, or custom element (see below) | | styles | ToastStyles.info | object | Styles for the container and text (see below) | | duration | 3000 | number | Duration in ms the toast is shown for | | height | 100 | number | Height of the toast message | | onShow | null | func | Callback called when this message is shown | | onHide | null | func | Callback called when this message is hidden | | onPress | null | func | Callback called when this message is pressed |

text

The text property can be either a simple string or a custom element to be rendered. If a string is passed, it is wrapped in a container View and Text element:

text = (
  <View>
    <Text>{text}</Text>
  </View>
)

Both the container View and Text element can be styled using the styles property.

styles

An object used to style the container View and Text elements when message.text is a string. Defaults to ToastStyles.info if not set and should look like this:

{
  container: {
    backgroundColor: '#2487DB',
    paddingTop: 25,
    paddingRight: 15,
    paddingBottom: 15,
    paddingLeft: 15
  },
  text: {
    color: '#ffffff',
    fontWeight: 'bold'
  }
}

Example with Redux

App.jsx

import React, { Component } from 'react'
import { View } from 'react-native'
import { connect } from 'react-redux'
import Toaster from 'react-native-toaster'

class App extends Component {
  render () {
    return (
      <View>
        <Toaster message={this.props.toastMessage} />
        <LoginForm />
      </View>
    )
  }
}

const mapStateToProps = ({ toastMessage }) => ({ toastMessage })
export default connect(mapStateToProps)(App)

LoginForm.jsx

import React, { Component } from 'react'
import { View, TextInput, TouchableHighlight } from 'react-native'
import { connect } from 'react-redux'
import { ToastStyles } from 'react-native-toaster'
import { addToast } from './redux/actions'
import styles from './styles'

class LoginForm extends Component {
  state = { email: '', password: '' }

  onEmailChange = (email) => this.setState({ email })
  onPasswordChange = (password) => this.setState({ password })

  onLoginButtonPress = () => {
    const { email, password } = this.state

    // TODO: Send to server, on response call addToast:

    this.props.addToast({
      text: 'Successfully logged in',
      styles: ToastStyles.success
    })

    // --- or ---

    this.props.addToast({
      text: 'Login failed, check your email or password',
      styles: ToastStyles.error
    })
  }

  render () {
    return (
      <View>
        <TextInput onChangeText={this.onEmailChange} value={this.state.email} placeholder='Email' />
        <TextInput onChangeText={this.onPasswordChange} value={this.state.password} placeholder='Password' />
        <TouchableHighlight onPress={this.onLoginButtonPress}>
          <Text>Login</Text>
        </TouchableHighlight>
      </View>
    )
  }
}

const mapDispatchToProps = { addToast }
export default connect(null, mapDispatchToProps)(LoginForm)

redux/actions.js

export const ADD_TOAST = 'ADD_TOAST'
export function addToast (message) {
  return { type: ADD_TOAST, message }
}

redux/reducers.js

import { combineReducers } from 'redux'
import { ADD_TOAST } from './actions'

function toastMessage (state = null, action) {
  switch (action.type) {
    case ADD_TOAST:
      return action.message
    default:
      return state
  }
}

export default combineReducers({
  appState,
  toastMessage,
  connect: (state = null) => state
})

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

ISC © TABLEFLIP


A (╯°□°)╯︵TABLEFLIP side project.