Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashing when triggering again with the same action object #68

Open
antsmo opened this issue Mar 19, 2018 · 4 comments
Open

Crashing when triggering again with the same action object #68

antsmo opened this issue Mar 19, 2018 · 4 comments
Labels

Comments

@antsmo
Copy link

antsmo commented Mar 19, 2018

Description

I've created a lookup with some configs defined for different notifications and one button to show each one. It works fine until I tap the same button a second time and then I get an error message about the background color (see below).

I should add that this is from a completely fresh React Native project.

Example

// @flow

import React, { Component } from "react";
import { StyleSheet, Text, Button, View } from "react-native";
import Snackbar from "react-native-snackbar";

const NOTIFICATIONS = {
  CANCELLED: {
    title: "Cancelled",
    duration: Snackbar.LENGTH_INDEFINITE,
    backgroundColor: "#DA2446",
    action: {
      title: "View",
      onPress: () => null
    }
  },
  COMPLETED: {
    title: "Completed",
    duration: Snackbar.LENGTH_LONG,
    backgroundColor: "#3DC217"
  },
  REQUEST: {
    title: "New Request",
    duration: 5000,
    backgroundColor: "#5B408E",
    action: {
      title: "Open",
      onPress: () => null
    }
  }
};

export default class App extends Component<null> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Button
          title="Show Cancelled"
          onPress={() => Snackbar.show(NOTIFICATIONS.CANCELLED)}
        />
        <Button
          title="Show Completed"
          onPress={() => Snackbar.show(NOTIFICATIONS.COMPLETED)}
        />
        <Button
          title="Show Request"
          onPress={() => Snackbar.show(NOTIFICATIONS.REQUEST)}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  welcome: {
    fontSize: 20,
    textAlign: "center",
    margin: 10
  }
});

simulator screen shot - iphone 6 - 2018-03-19 at 10 57 41

@cooperka
Copy link
Owner

Hi @MyGuySi, that's very strange! I wonder if it's related to re-using the same config object? Can you try the following:

const NOTIFICATIONS = {
  get CANCELLED() {
    return {
      title: "Cancelled",
      duration: Snackbar.LENGTH_INDEFINITE,
      backgroundColor: "#DA2446",
      action: {
        title: "View",
        onPress: () => null
      }
    };
  },
  get COMPLETED() {
    return {
      title: "Completed",
      duration: Snackbar.LENGTH_LONG,
      backgroundColor: "#3DC217"
    };
  },
  get REQUEST() {
    return {
      title: "New Request",
      duration: 5000,
      backgroundColor: "#5B408E",
      action: {
        title: "Open",
        onPress: () => null
      }
    };
  }
};

Please let me know if this changes anything. Otherwise, if you could link to a working example app I'd like to try it myself. Thanks.

@antsmo
Copy link
Author

antsmo commented Mar 20, 2018

Hi @cooperka, yep I tried out your suggestion and that does indeed fix it 🤔

@cooperka cooperka added the bug label Mar 21, 2018
@cooperka
Copy link
Owner

Thank you for confirming! This bug should certainly be fixed, but luckily it's rare and easily worked around. I'd welcome a PR to address it if you have the time.

@antsmo
Copy link
Author

antsmo commented Mar 22, 2018

I'm not using react-native-snackbar in any of my projects currently, it was more of a research exercise so I may not be able to submit a PR straight away but if we decide to use it then I'll definitely take a stab at it 👍

@cooperka cooperka changed the title Crashing when triggering the same action twice Crashing when triggering again with the same action object Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants