0

我想将 android 本机模块中的 DatePickerDialog 用于 react-native 应用程序,但我遇到了一些问题:

  1. 我不能调用 getSupportFragmentManager(),所以我不能使用 MaterialDatePicker
  2. getReactApplicationContext() 返回空令牌,无法添加窗口

有人知道如何为 DatePickerDialog 获取 ReactApplicationContext 吗?

    package com.project4;
    import com.facebook.react.bridge.NativeModule;
    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.Callback;
    
    import com.google.android.material.datepicker.MaterialDatePicker;
    import androidx.fragment.app.FragmentActivity;
    import android.app.DatePickerDialog;
    import android.widget.Toast;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class AndroidNativeCalendarModule extends ReactContextBaseJavaModule{
        private static ReactApplicationContext reactContext;
        
        AndroidNativeCalendarModule(ReactApplicationContext context){
            super(context);
            reactContext = context;
    
        }
    
        @Override
        public String getName(){
            return "AndroidNativeCalendar";
        }
        @ReactMethod
        public void CalendarOnCreate(){
            // MaterialDatePicker.Builder.datePicker().build().show(reactContext.getCurrentActivity().getSupportFragmentManager(), "");// <-- can't find symbol
            new DatePickerDialog(getReactApplicationContext()).show();// <-- null token
            Toast.makeText(getReactApplicationContext(), "Test", Toast.LENGTH_SHORT).show(); // <-- can show toast message without error
        }
    }

React Native Android 原生模块 DatePickerDialog

4

0 回答 0