PickerViewModule.java 19.1 KB
Newer Older
xwenliang's avatar
xwenliang committed
1 2 3
package com.beefe.picker;

import android.app.Activity;
4
import android.app.Dialog;
xwenliang's avatar
xwenliang committed
5
import android.graphics.Color;
6
import android.graphics.PixelFormat;
xwenliang's avatar
xwenliang committed
7 8 9 10
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
11
import android.view.Window;
xwenliang's avatar
xwenliang committed
12 13 14 15
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

travelgeezer's avatar
travelgeezer committed
16
import com.beefe.picker.util.MIUIUtils;
xwenliang's avatar
xwenliang committed
17 18 19
import com.beefe.picker.view.OnSelectedListener;
import com.beefe.picker.view.PickerViewAlone;
import com.beefe.picker.view.PickerViewLinkage;
xwenliang's avatar
xwenliang committed
20
import com.beefe.picker.view.ReturnData;
xwenliang's avatar
xwenliang committed
21 22
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
xwenliang's avatar
xwenliang committed
23
import com.facebook.react.bridge.LifecycleEventListener;
xwenliang's avatar
xwenliang committed
24 25 26 27 28 29 30 31 32 33 34 35
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.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.util.ArrayList;

xwenliang's avatar
xwenliang committed
36 37
import static android.graphics.Color.argb;

xwenliang's avatar
xwenliang committed
38
/**
xwenliang's avatar
xwenliang committed
39
 * Author: <a href="https://github.com/shexiaoheng">heng</a>
40
 * <p>
xwenliang's avatar
xwenliang committed
41
 * Created by heng on 16/9/5.
42
 * <p>
xwenliang's avatar
xwenliang committed
43
 * Edited by heng on 16/9/22.
44 45
 * 1. PopupWindow height : full screen -> assignation
 * 2. Added pickerToolBarHeight support
46
 * <p>
47 48 49
 * Edited by heng on 2016/10/19.
 * 1. Added weights support
 * 2. Fixed return data bug
50 51 52 53 54 55 56 57 58
 * <p>
 * Edited by heng on 2016/11/16.
 * 1. Used WindowManager replace PopupWindow
 * 2. Removed method initOK() toggle() show() isPickerShow()
 * 3. Implements Application.ActivityLifecycleCallbacks
 * <p>
 * Edited by heng on 2016/11/17
 * 1. Used Dialog replace WindowManger
 * 2. Restore method show() isPickerShow()
xwenliang's avatar
xwenliang committed
59 60 61 62
 * <p>
 * Edited by heng on 2016/12/23
 * 1. Changed returnData type
 * 2. Added pickerToolBarFontSize
xwenliang's avatar
xwenliang committed
63
 * <p>
xwenliang's avatar
xwenliang committed
64 65 66 67 68 69
 * Edited by heng on 2016/12/26
 * 1. Fixed returnData bug
 * 2. Added pickerFontColor
 * 3. Added pickerFontSize
 * 4. Used LifecycleEventListener replace Application.ActivityLifecycleCallbacks
 * 5. Fixed other bug
xwenliang's avatar
xwenliang committed
70 71 72 73
 *
 * Edited by heng on 2017/01/17
 * 1. Added select(ReadableArray array, Callback callback)
 * 2. Optimization code
xwenliang's avatar
xwenliang committed
74 75
 */

xwenliang's avatar
xwenliang committed
76
public class PickerViewModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
xwenliang's avatar
xwenliang committed
77 78 79 80 81

    private static final String REACT_CLASS = "BEEPickerManager";

    private static final String PICKER_DATA = "pickerData";
    private static final String SELECTED_VALUE = "selectedValue";
82

xwenliang's avatar
xwenliang committed
83
    private static final String IS_LOOP = "isLoop";
84 85 86

    private static final String WEIGHTS = "wheelFlex";

xwenliang's avatar
xwenliang committed
87
    private static final String PICKER_BG_COLOR = "pickerBg";
88

xwenliang's avatar
xwenliang committed
89 90 91
    private static final String PICKER_TOOL_BAR_BG = "pickerToolBarBg";
    private static final String PICKER_TOOL_BAR_HEIGHT = "pickerToolBarHeight";
    private static final String PICKER_TOOL_BAR_TEXT_SIZE = "pickerToolBarFontSize";
92

xwenliang's avatar
xwenliang committed
93 94
    private static final String PICKER_CONFIRM_BTN_TEXT = "pickerConfirmBtnText";
    private static final String PICKER_CONFIRM_BTN_COLOR = "pickerConfirmBtnColor";
95

xwenliang's avatar
xwenliang committed
96 97
    private static final String PICKER_CANCEL_BTN_TEXT = "pickerCancelBtnText";
    private static final String PICKER_CANCEL_BTN_COLOR = "pickerCancelBtnColor";
98

xwenliang's avatar
xwenliang committed
99 100 101 102 103
    private static final String PICKER_TITLE_TEXT = "pickerTitleText";
    private static final String PICKER_TITLE_TEXT_COLOR = "pickerTitleColor";

    private static final String PICKER_TEXT_COLOR = "pickerFontColor";
    private static final String PICKER_TEXT_SIZE = "pickerFontSize";
104
    private static final String PICKER_TEXT_ELLIPSIS_LEN = "pickerTextEllipsisLen";
xwenliang's avatar
xwenliang committed
105 106 107 108 109 110

    private static final String PICKER_EVENT_NAME = "pickerEvent";
    private static final String EVENT_KEY_CONFIRM = "confirm";
    private static final String EVENT_KEY_CANCEL = "cancel";
    private static final String EVENT_KEY_SELECTED = "select";

xwenliang's avatar
xwenliang committed
111
    private static final String ERROR_NOT_INIT = "please initialize the component first";
xwenliang's avatar
xwenliang committed
112

113
    private Dialog dialog = null;
xwenliang's avatar
xwenliang committed
114 115 116 117 118 119

    private boolean isLoop = true;

    private String confirmText;
    private String cancelText;
    private String titleText;
120
    private int pickerTextEllipsisLen;
xwenliang's avatar
xwenliang committed
121

122 123
    private double[] weights;

xwenliang's avatar
xwenliang committed
124
    private ArrayList<ReturnData> returnData;
xwenliang's avatar
xwenliang committed
125

126
    private int curStatus;
xwenliang's avatar
xwenliang committed
127

xwenliang's avatar
xwenliang committed
128 129 130
    private PickerViewLinkage pickerViewLinkage;
    private PickerViewAlone pickerViewAlone;

xwenliang's avatar
xwenliang committed
131 132
    public PickerViewModule(ReactApplicationContext reactContext) {
        super(reactContext);
xwenliang's avatar
xwenliang committed
133
        reactContext.addLifecycleEventListener(this);
xwenliang's avatar
xwenliang committed
134 135 136 137 138 139 140 141 142 143 144
    }

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @ReactMethod
    public void _init(ReadableMap options) {
        Activity activity = getCurrentActivity();
        if (activity != null && options.hasKey(PICKER_DATA)) {
145
            View view = activity.getLayoutInflater().inflate(R.layout.picker_view, null);
146 147 148 149
            RelativeLayout barLayout = (RelativeLayout) view.findViewById(R.id.barLayout);
            TextView cancelTV = (TextView) view.findViewById(R.id.cancel);
            TextView titleTV = (TextView) view.findViewById(R.id.title);
            TextView confirmTV = (TextView) view.findViewById(R.id.confirm);
150
            RelativeLayout pickerLayout = (RelativeLayout) view.findViewById(R.id.pickerLayout);
jinlongtao's avatar
jinlongtao committed
151 152
            pickerViewLinkage = (PickerViewLinkage) view.findViewById(R.id.pickerViewLinkage);
            pickerViewAlone = (PickerViewAlone) view.findViewById(R.id.pickerViewAlone);
153 154

            int barViewHeight;
xwenliang's avatar
xwenliang committed
155
            if (options.hasKey(PICKER_TOOL_BAR_HEIGHT)) {
xwenliang's avatar
xwenliang committed
156
                try {
xwenliang's avatar
xwenliang committed
157
                    barViewHeight = options.getInt(PICKER_TOOL_BAR_HEIGHT);
xwenliang's avatar
xwenliang committed
158
                } catch (Exception e) {
xwenliang's avatar
xwenliang committed
159
                    barViewHeight = (int) options.getDouble(PICKER_TOOL_BAR_HEIGHT);
xwenliang's avatar
xwenliang committed
160
                }
xwenliang's avatar
xwenliang committed
161 162 163 164 165 166 167
            } else {
                barViewHeight = (int) (activity.getResources().getDisplayMetrics().density * 40);
            }
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT,
                    barViewHeight);
            barLayout.setLayoutParams(params);
xwenliang's avatar
xwenliang committed
168

xwenliang's avatar
xwenliang committed
169 170
            if (options.hasKey(PICKER_TOOL_BAR_BG)) {
                ReadableArray array = options.getArray(PICKER_TOOL_BAR_BG);
171
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
172
                barLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
173 174
            }

xwenliang's avatar
xwenliang committed
175 176 177 178 179 180
            if (options.hasKey(PICKER_TOOL_BAR_TEXT_SIZE)) {
                int toolBarTextSize = options.getInt(PICKER_TOOL_BAR_TEXT_SIZE);
                cancelTV.setTextSize(toolBarTextSize);
                titleTV.setTextSize(toolBarTextSize);
                confirmTV.setTextSize(toolBarTextSize);
            }
xwenliang's avatar
xwenliang committed
181

xwenliang's avatar
xwenliang committed
182 183
            if (options.hasKey(PICKER_CONFIRM_BTN_TEXT)) {
                confirmText = options.getString(PICKER_CONFIRM_BTN_TEXT);
xwenliang's avatar
xwenliang committed
184 185 186
            }
            confirmTV.setText(!TextUtils.isEmpty(confirmText) ? confirmText : "");

xwenliang's avatar
xwenliang committed
187 188
            if (options.hasKey(PICKER_CONFIRM_BTN_COLOR)) {
                ReadableArray array = options.getArray(PICKER_CONFIRM_BTN_COLOR);
189
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
190
                confirmTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
191 192 193 194
            }
            confirmTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
195
                    switch (curStatus) {
196 197 198 199 200 201 202
                        case 0:
                            returnData = pickerViewAlone.getSelectedData();
                            break;
                        case 1:
                            returnData = pickerViewLinkage.getSelectedData();
                            break;
                    }
xwenliang's avatar
xwenliang committed
203 204 205 206 207 208
                    commonEvent(EVENT_KEY_CONFIRM);
                    hide();
                }
            });


xwenliang's avatar
xwenliang committed
209 210
            if (options.hasKey(PICKER_TITLE_TEXT)) {
                titleText = options.getString(PICKER_TITLE_TEXT);
xwenliang's avatar
xwenliang committed
211 212
            }
            titleTV.setText(!TextUtils.isEmpty(titleText) ? titleText : "");
xwenliang's avatar
xwenliang committed
213 214
            if (options.hasKey(PICKER_TITLE_TEXT_COLOR)) {
                ReadableArray array = options.getArray(PICKER_TITLE_TEXT_COLOR);
215
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
216
                titleTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
217 218
            }

xwenliang's avatar
xwenliang committed
219 220
            if (options.hasKey(PICKER_CANCEL_BTN_TEXT)) {
                cancelText = options.getString(PICKER_CANCEL_BTN_TEXT);
xwenliang's avatar
xwenliang committed
221 222
            }
            cancelTV.setText(!TextUtils.isEmpty(cancelText) ? cancelText : "");
xwenliang's avatar
xwenliang committed
223 224
            if (options.hasKey(PICKER_CANCEL_BTN_COLOR)) {
                ReadableArray array = options.getArray(PICKER_CANCEL_BTN_COLOR);
225
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
226
                cancelTV.setTextColor(argb(colors[3], colors[0], colors[1], colors[2]));
xwenliang's avatar
xwenliang committed
227 228 229 230
            }
            cancelTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
231
                    switch (curStatus) {
232 233 234 235 236 237 238
                        case 0:
                            returnData = pickerViewAlone.getSelectedData();
                            break;
                        case 1:
                            returnData = pickerViewLinkage.getSelectedData();
                            break;
                    }
xwenliang's avatar
xwenliang committed
239 240 241 242 243
                    commonEvent(EVENT_KEY_CANCEL);
                    hide();
                }
            });

244 245 246 247
            if(options.hasKey(PICKER_TEXT_ELLIPSIS_LEN)){
                pickerTextEllipsisLen = options.getInt(PICKER_TEXT_ELLIPSIS_LEN);
            }

xwenliang's avatar
xwenliang committed
248 249 250 251
            if (options.hasKey(IS_LOOP)) {
                isLoop = options.getBoolean(IS_LOOP);
            }

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
            if (options.hasKey(WEIGHTS)) {
                ReadableArray array = options.getArray(WEIGHTS);
                weights = new double[array.size()];
                for (int i = 0; i < array.size(); i++) {
                    switch (array.getType(i).name()) {
                        case "Number":
                            try {
                                weights[i] = array.getInt(i);
                            } catch (Exception e) {
                                weights[i] = array.getDouble(i);
                            }
                            break;
                        case "String":
                            try {
                                weights[i] = Double.parseDouble(array.getString(i));
                            } catch (Exception e) {
                                weights[i] = 1.0;
                            }
                            break;
                        default:
                            weights[i] = 1.0;
                            break;
                    }
                }
            }

xwenliang's avatar
xwenliang committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
            int pickerTextColor = 0xff000000;
            if (options.hasKey(PICKER_TEXT_COLOR)) {
                ReadableArray array = options.getArray(PICKER_TEXT_COLOR);
                int[] colors = getColor(array);
                pickerTextColor = Color.argb(colors[3], colors[0], colors[1], colors[2]);
            }

            int pickerTextSize = 16;
            if (options.hasKey(PICKER_TEXT_SIZE)) {
                try {
                    pickerTextSize = options.getInt(PICKER_TEXT_SIZE);
                } catch (Exception e) {
                    pickerTextSize = (int) options.getDouble(PICKER_TEXT_SIZE);
                }
            }

xwenliang's avatar
xwenliang committed
294 295
            ReadableArray pickerData = options.getArray(PICKER_DATA);

296
            int pickerViewHeight;
xwenliang's avatar
xwenliang committed
297 298
            String name = pickerData.getType(0).name();
            switch (name) {
xwenliang's avatar
xwenliang committed
299
                case "Map":
300
                    curStatus = 1;
xwenliang's avatar
xwenliang committed
301 302
                    pickerViewLinkage.setVisibility(View.VISIBLE);
                    pickerViewAlone.setVisibility(View.GONE);
303

304
                    pickerViewLinkage.setPickerData(pickerData, weights);
xwenliang's avatar
xwenliang committed
305 306
                    pickerViewLinkage.setTextColor(pickerTextColor);
                    pickerViewLinkage.setTextSize(pickerTextSize);
307
                    pickerViewLinkage.setTextEllipsisLen(pickerTextEllipsisLen);
xwenliang's avatar
xwenliang committed
308
                    pickerViewLinkage.setIsLoop(isLoop);
309

xwenliang's avatar
xwenliang committed
310 311
                    pickerViewLinkage.setOnSelectListener(new OnSelectedListener() {
                        @Override
xwenliang's avatar
xwenliang committed
312
                        public void onSelected(ArrayList<ReturnData> selectedList) {
313
                            returnData = selectedList;
xwenliang's avatar
xwenliang committed
314 315 316
                            commonEvent(EVENT_KEY_SELECTED);
                        }
                    });
xwenliang's avatar
xwenliang committed
317
                    pickerViewHeight = pickerViewLinkage.getViewHeight();
xwenliang's avatar
xwenliang committed
318
                    break;
xwenliang's avatar
xwenliang committed
319
                default:
320
                    curStatus = 0;
xwenliang's avatar
xwenliang committed
321 322
                    pickerViewAlone.setVisibility(View.VISIBLE);
                    pickerViewLinkage.setVisibility(View.GONE);
xwenliang's avatar
xwenliang committed
323

324
                    pickerViewAlone.setPickerData(pickerData, weights);
xwenliang's avatar
xwenliang committed
325 326
                    pickerViewAlone.setTextColor(pickerTextColor);
                    pickerViewAlone.setTextSize(pickerTextSize);
327
                    pickerViewAlone.setTextEllipsisLen(pickerTextEllipsisLen);
xwenliang's avatar
xwenliang committed
328 329 330 331
                    pickerViewAlone.setIsLoop(isLoop);

                    pickerViewAlone.setOnSelectedListener(new OnSelectedListener() {
                        @Override
xwenliang's avatar
xwenliang committed
332
                        public void onSelected(ArrayList<ReturnData> selectedList) {
333
                            returnData = selectedList;
xwenliang's avatar
xwenliang committed
334 335 336 337
                            commonEvent(EVENT_KEY_SELECTED);
                        }
                    });

xwenliang's avatar
xwenliang committed
338
                    pickerViewHeight = pickerViewAlone.getViewHeight();
xwenliang's avatar
xwenliang committed
339 340 341
                    break;
            }

xwenliang's avatar
xwenliang committed
342 343 344 345 346 347
            if (options.hasKey(SELECTED_VALUE)) {
                ReadableArray array = options.getArray(SELECTED_VALUE);
                String[] selectedValue = getSelectedValue(array);
                select(selectedValue);
            }

348 349 350
            if (options.hasKey(PICKER_BG_COLOR)) {
                ReadableArray array = options.getArray(PICKER_BG_COLOR);
                int[] colors = getColor(array);
xwenliang's avatar
xwenliang committed
351
                pickerLayout.setBackgroundColor(argb(colors[3], colors[0], colors[1], colors[2]));
352 353 354 355 356
            }

            int height = barViewHeight + pickerViewHeight;
            if (dialog == null) {
                dialog = new Dialog(activity, R.style.Dialog_Full_Screen);
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                dialog.setContentView(view);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                Window window = dialog.getWindow();
                if (window != null) {
                    if (MIUIUtils.isMIUI()) {
                        layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
                    }else {
                        //layoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
                    }
                    layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
                    layoutParams.format = PixelFormat.TRANSPARENT;
                    layoutParams.windowAnimations = R.style.PickerAnim;
                    layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
                    layoutParams.height = height;
                    layoutParams.gravity = Gravity.BOTTOM;
                    window.setAttributes(layoutParams);
                }
374
            } else {
375
                dialog.dismiss();
376
                dialog.setContentView(view);
xwenliang's avatar
xwenliang committed
377 378 379 380
            }
        }
    }

xwenliang's avatar
xwenliang committed
381 382 383 384 385 386 387 388 389 390 391 392
    @ReactMethod
    public void select(ReadableArray array, Callback callback) {
        if (dialog == null) {
            if (callback != null) {
                callback.invoke(ERROR_NOT_INIT);
            }
            return;
        }
        String[] selectedValue = getSelectedValue(array);
        select(selectedValue);
    }

xwenliang's avatar
xwenliang committed
393
    @ReactMethod
394 395
    public void show() {
        if (dialog == null) {
xwenliang's avatar
xwenliang committed
396 397
            return;
        }
398 399
        if (!dialog.isShowing()) {
            dialog.show();
xwenliang's avatar
xwenliang committed
400 401 402 403 404
        }
    }

    @ReactMethod
    public void hide() {
405 406 407 408 409
        if (dialog == null) {
            return;
        }
        if (dialog.isShowing()) {
            dialog.dismiss();
xwenliang's avatar
xwenliang committed
410 411 412 413 414
        }
    }

    @ReactMethod
    public void isPickerShow(Callback callback) {
xwenliang's avatar
xwenliang committed
415 416
        if (callback == null)
            return;
417
        if (dialog == null) {
xwenliang's avatar
xwenliang committed
418 419
            callback.invoke(ERROR_NOT_INIT);
        } else {
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
            callback.invoke(null, dialog.isShowing());
        }
    }

    private int[] getColor(ReadableArray array) {
        int[] colors = new int[4];
        for (int i = 0; i < array.size(); i++) {
            switch (i) {
                case 0:
                case 1:
                case 2:
                    colors[i] = array.getInt(i);
                    break;
                case 3:
                    colors[i] = (int) (array.getDouble(i) * 255);
                    break;
                default:
                    break;
            }
xwenliang's avatar
xwenliang committed
439
        }
440
        return colors;
xwenliang's avatar
xwenliang committed
441 442
    }

xwenliang's avatar
xwenliang committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    private String[] getSelectedValue(ReadableArray array) {
        String[] selectValue = new String[array.size()];
        String value = "";
        for (int i = 0; i < array.size(); i++) {
            switch (array.getType(i).name()) {
                case "Boolean":
                    value = String.valueOf(array.getBoolean(i));
                    break;
                case "Number":
                    try {
                        value = String.valueOf(array.getInt(i));
                    } catch (Exception e) {
                        value = String.valueOf(array.getDouble(i));
                    }
                    break;
                case "String":
                    value = array.getString(i);
                    break;
            }
            selectValue[i] = value;
        }
        return selectValue;
    }

    private void select(String[] selectedValue) {
        switch (curStatus) {
            case 0:
                pickerViewAlone.setSelectValue(selectedValue);
                break;
            case 1:
                pickerViewLinkage.setSelectValue(selectedValue);
                break;
        }
    }

xwenliang's avatar
xwenliang committed
478 479
    private void commonEvent(String eventKey) {
        WritableMap map = Arguments.createMap();
xwenliang's avatar
xwenliang committed
480 481 482 483 484 485
        map.putString("type", eventKey);
        WritableArray indexes = Arguments.createArray();
        WritableArray values = Arguments.createArray();
        for (ReturnData data : returnData) {
            indexes.pushInt(data.getIndex());
            values.pushString(data.getItem());
xwenliang's avatar
xwenliang committed
486
        }
xwenliang's avatar
xwenliang committed
487 488
        map.putArray("selectedValue", values);
        map.putArray("selectedIndex", indexes);
xwenliang's avatar
xwenliang committed
489 490 491 492 493 494 495 496 497 498
        sendEvent(getReactApplicationContext(), PICKER_EVENT_NAME, map);
    }

    private void sendEvent(ReactContext reactContext,
                           String eventName,
                           @Nullable WritableMap params) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }
499 500

    @Override
xwenliang's avatar
xwenliang committed
501
    public void onHostResume() {
502 503 504 505

    }

    @Override
xwenliang's avatar
xwenliang committed
506
    public void onHostPause() {
507
        hide();
xwenliang's avatar
xwenliang committed
508
        dialog = null;
509 510 511
    }

    @Override
xwenliang's avatar
xwenliang committed
512
    public void onHostDestroy() {
513 514
        hide();
        dialog = null;
515
    }
xwenliang's avatar
xwenliang committed
516
}