package com.lugg.ReactSnackbar;

import android.app.Activity;
import android.util.Log;
import android.view.View;

import android.support.design.widget.Snackbar;

import com.facebook.react.common.ReactConstants;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Callback;

import java.util.Map;
import java.util.HashMap;

public class ReactSnackbarModule extends ReactContextBaseJavaModule {
  private View mRootView = null;

  private static final String LENGTH_SHORT = "SHORT";
  private static final String LENGTH_LONG = "LONG";
  private static final String LENGTH_INDEFINITE = "INDEFINITE";

  public ReactSnackbarModule(ReactApplicationContext reactContext, View rootView) {
    super(reactContext);
    mRootView = rootView;
  }

  @Override
  public String getName() {
    return "SnackbarAndroid";
  }

  @Override
  public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();
    constants.put(LENGTH_SHORT, Snackbar.LENGTH_SHORT);
    constants.put(LENGTH_LONG, Snackbar.LENGTH_LONG);
    constants.put(LENGTH_INDEFINITE, Snackbar.LENGTH_INDEFINITE);
    return constants;
  }

  @ReactMethod
  public void show(String message, int length, boolean hideOnClick, int color, String actionLabel, final Callback actionCallback) {
    final Snackbar snackbar = Snackbar.make(mRootView, message, length);

    snackbar.setActionTextColor(color);

    if (hideOnClick) {
      snackbar.setAction("Dismiss", new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          snackbar.dismiss();
        }
      });
    }
    else if (actionLabel != null && actionCallback != null) {
      snackbar.setAction(actionLabel, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          snackbar.dismiss();
          actionCallback.invoke();
        }
      });
    }

    snackbar.show();
  }
}

@@ -107,16 +107,79 @@
 .View;%0A%0A
+import android.graphics.Color;%0Aimport android.widget.TextView;%0A
 import a
@@ -893,16 +893,138 @@
 NITE%22;%0A%0A
+  private static final int COLOR_BACKGROUND = -13487566; // #323232%0A  private static final int COLOR_TEXT = Color.WHITE;%0A%0A
   public
@@ -1637,17 +1637,23 @@
 ck, int 
-c
+actionC
 olor, St
@@ -1773,24 +1773,362 @@
 , length);%0A%0A
+    // enforce snackbar background/text color so it doesn't inherit from styles.xml%0A    View snackbarView = snackbar.getView();%0A    snackbarView.setBackgroundColor(COLOR_BACKGROUND);%0A    TextView textView = (TextView) snackbarView.findViewById(R.id.snackbar_text);%0A    textView.setTextColor(COLOR_TEXT);%0A%0A    // set a custom action color%0A
     snackbar
@@ -2147,17 +2147,23 @@
 xtColor(
-c
+actionC
 olor);%0A%0A

enforce snackbar background and text colors