-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): material 3 pickers (#952)
* Support Kotlin files Android Studio recommended these settings for supporting Kotlin in the project. * Add Material dependency * Extract re-usable picker argument utilities The new Material pickers will utilize these utilities as well. * Set up new specs/modules * Accept new arguments for Material pickers The pickers will allow the user to set a title for the dialog and specify if the initial input mode should be a text input or calendar/clock. * Implement MaterialDatePicker This also adds a utility function to RNDate to get the date in milliseconds. * Implement MaterialTimePicker * Create JS connectors that call the native modules * Choose native module based on `design` prop If the `design` is "material", then use the Material modules. Otherwise, use the default modules. * Validate Material 3 props not used with default pickers * Update components to pass new props to modules * Update types * Update example app * Fix typo in existing docs * Add dummy files to prevent tests from failing The tests were trying to access the native modules. These dummy files will make sure the tests don't try accessing the real implementations that end with `.android.js`. * Update README * Update E2E specs Since there are multiple "default" options on the screen now, I've specified to tap the first one. I also had to make sure to scroll the screen before tapping the show picker button. * Make example app inherit from Material3 theme * Move post-install into `start` script
- Loading branch information
1 parent
e5664b7
commit e81c6a1
Showing
35 changed files
with
1,229 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
android/src/main/java/com/reactcommunity/rndatetimepicker/MaterialDatePickerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.reactcommunity.rndatetimepicker | ||
|
||
import androidx.fragment.app.FragmentActivity | ||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.UiThreadUtil | ||
import com.reactcommunity.rndatetimepicker.Common.createDatePickerArguments | ||
import com.reactcommunity.rndatetimepicker.Common.dismissDialog | ||
|
||
class MaterialDatePickerModule(reactContext: ReactApplicationContext): NativeModuleMaterialDatePickerSpec(reactContext) { | ||
companion object { | ||
const val NAME = "RNCMaterialDatePicker" | ||
} | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
override fun dismiss(promise: Promise?) { | ||
val activity = currentActivity as FragmentActivity? | ||
dismissDialog(activity, NAME, promise) | ||
} | ||
|
||
override fun open(params: ReadableMap, promise: Promise) { | ||
val activity = currentActivity as FragmentActivity? | ||
if (activity == null) { | ||
promise.reject( | ||
RNConstants.ERROR_NO_ACTIVITY, | ||
"Tried to open a MaterialDatePicker dialog while not attached to an Activity" | ||
) | ||
return | ||
} | ||
|
||
val fragmentManager = activity.supportFragmentManager | ||
|
||
UiThreadUtil.runOnUiThread { | ||
val arguments = createDatePickerArguments(params) | ||
val datePicker = | ||
RNMaterialDatePicker(arguments, promise, fragmentManager, reactApplicationContext) | ||
datePicker.open() | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
android/src/main/java/com/reactcommunity/rndatetimepicker/MaterialTimePickerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.reactcommunity.rndatetimepicker | ||
|
||
import androidx.fragment.app.FragmentActivity | ||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.UiThreadUtil | ||
import com.reactcommunity.rndatetimepicker.Common.createTimePickerArguments | ||
import com.reactcommunity.rndatetimepicker.Common.dismissDialog | ||
|
||
class MaterialTimePickerModule(reactContext: ReactApplicationContext) : | ||
NativeModuleMaterialTimePickerSpec(reactContext) { | ||
companion object { | ||
const val NAME = "RNCMaterialTimePicker" | ||
} | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
override fun dismiss(promise: Promise?) { | ||
val activity = currentActivity as FragmentActivity? | ||
dismissDialog(activity, NAME, promise) | ||
} | ||
|
||
override fun open(params: ReadableMap, promise: Promise) { | ||
val activity = currentActivity as FragmentActivity? | ||
if (activity == null) { | ||
promise.reject( | ||
RNConstants.ERROR_NO_ACTIVITY, | ||
"Tried to open a MaterialTimePicker dialog while not attached to an Activity" | ||
) | ||
} | ||
|
||
val fragmentManager = activity!!.supportFragmentManager | ||
|
||
UiThreadUtil.runOnUiThread { | ||
val arguments = | ||
createTimePickerArguments(params) | ||
val materialPicker = RNMaterialTimePicker( | ||
arguments, | ||
promise, | ||
fragmentManager, | ||
reactApplicationContext | ||
) | ||
materialPicker.open() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.