Skip to content

Commit

Permalink
Merge pull request #82 from rayhannabi/hotfix/datepicker-range
Browse files Browse the repository at this point in the history
Add max date and min date to date picker
  • Loading branch information
rayhannabi committed Oct 11, 2019
2 parents f68fd6c + a21d6bf commit 6852845
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 20 deletions.
8 changes: 4 additions & 4 deletions RNAlertController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 680;
CURRENT_PROJECT_VERSION = 681;
DEVELOPMENT_TEAM = PCH85ZHVFN;
INFOPLIST_FILE = "$(SRCROOT)/RNAlertControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
Expand All @@ -555,7 +555,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 680;
CURRENT_PROJECT_VERSION = 681;
DEVELOPMENT_TEAM = PCH85ZHVFN;
INFOPLIST_FILE = "$(SRCROOT)/RNAlertControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
Expand Down Expand Up @@ -702,7 +702,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1004;
CURRENT_PROJECT_VERSION = 1005;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = PCH85ZHVFN;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -734,7 +734,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1004;
CURRENT_PROJECT_VERSION = 1005;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = PCH85ZHVFN;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class OtherViewController: UIViewController {
@IBAction func didTapChooseDate(_ sender: UIButton) {
RNAlertController(title: "Pick a date",
message: "This date will be selected when you tap Done")
.setDatePicker(mode: .date, date: selectedDate) { date in
.setDatePicker(mode: .date,
selectedDate: selectedDate,
maximumDate: Date()) { date in
self.selectedDate = date
let formatter = DateFormatter()
formatter.dateFormat = "dd MMMM yyyy"
Expand Down
12 changes: 9 additions & 3 deletions Source/RNAlertController+API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ public extension RNAlertController {
/// A date picker is placed under the message body.
/// - Parameters:
/// - mode: `UIDatePicker.Mode` describing the mode displayed the date picker.
/// - date: `Date` to set. If passed `nil`, current date is used.
/// - selectedDate: `Date` to set. If passed `nil`, current date is used.
/// - maximumDate: Maximum date that a date picker can show.
/// - minimumDate: Minimum date that a date picker can show.
/// - selectionAction: Block to execute when date is selected.
/// - Returns: `RNAlertController` instance.
@discardableResult
func setDatePicker(mode: UIDatePicker.Mode,
date: Date? = nil,
selectedDate: Date? = nil,
maximumDate: Date? = nil,
minimumDate: Date? = nil,
selectionAction: AlertDatePickerAction? = nil) -> RNAlertController {
alertDatePicker = AlertDatePicker(datePickerMode: mode, selectedDate: date)
alertDatePicker = AlertDatePicker(datePickerMode: mode, selectedDate: selectedDate)
alertDatePicker?.maximumDate = maximumDate
alertDatePicker?.minimumDate = minimumDate
alertDatePicker?.action = selectionAction
return self
}
Expand Down
36 changes: 31 additions & 5 deletions docs/Classes/RNAlertController.html
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ <h4>Return Value</h4>
<li class="item">
<div>
<code>
<a name="/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:date:selectionAction:"></a>
<a name="//apple_ref/swift/Method/setDatePicker(mode:date:selectionAction:)" class="dashAnchor"></a>
<a class="token" href="#/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:date:selectionAction:">setDatePicker(mode:date:selectionAction:)</a>
<a name="/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:selectedDate:maximumDate:minimumDate:selectionAction:"></a>
<a name="//apple_ref/swift/Method/setDatePicker(mode:selectedDate:maximumDate:minimumDate:selectionAction:)" class="dashAnchor"></a>
<a class="token" href="#/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:selectedDate:maximumDate:minimumDate:selectionAction:">setDatePicker(mode:selectedDate:maximumDate:minimumDate:selectionAction:)</a>
</code>
</div>
<div class="height-container">
Expand All @@ -735,7 +735,9 @@ <h4>Declaration</h4>
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="kd">func</span> <span class="nf">setDatePicker</span><span class="p">(</span><span class="nv">mode</span><span class="p">:</span> <span class="kt">UIDatePicker</span><span class="o">.</span><span class="kt">Mode</span><span class="p">,</span>
<span class="nv">date</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">selectedDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">maximumDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">minimumDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">selectionAction</span><span class="p">:</span> <span class="kt"><a href="../Typealiases.html#/s:17RNAlertController21AlertDatePickerActiona">AlertDatePickerAction</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">RNAlertController</span></code></pre>

</div>
Expand All @@ -759,7 +761,7 @@ <h4>Parameters</h4>
<tr>
<td>
<code>
<em>date</em>
<em>selectedDate</em>
</code>
</td>
<td>
Expand All @@ -768,6 +770,30 @@ <h4>Parameters</h4>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>maximumDate</em>
</code>
</td>
<td>
<div>
<p>Maximum date that a date picker can show.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>minimumDate</em>
</code>
</td>
<td>
<div>
<p>Minimum date that a date picker can show.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ <h4>Return Value</h4>
<li class="item">
<div>
<code>
<a name="/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:date:selectionAction:"></a>
<a name="//apple_ref/swift/Method/setDatePicker(mode:date:selectionAction:)" class="dashAnchor"></a>
<a class="token" href="#/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:date:selectionAction:">setDatePicker(mode:date:selectionAction:)</a>
<a name="/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:selectedDate:maximumDate:minimumDate:selectionAction:"></a>
<a name="//apple_ref/swift/Method/setDatePicker(mode:selectedDate:maximumDate:minimumDate:selectionAction:)" class="dashAnchor"></a>
<a class="token" href="#/c:@CM@RNAlertController@objc(cs)RNAlertController(im)setDatePickerWithMode:selectedDate:maximumDate:minimumDate:selectionAction:">setDatePicker(mode:selectedDate:maximumDate:minimumDate:selectionAction:)</a>
</code>
</div>
<div class="height-container">
Expand All @@ -735,7 +735,9 @@ <h4>Declaration</h4>
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">@discardableResult</span>
<span class="kd">func</span> <span class="nf">setDatePicker</span><span class="p">(</span><span class="nv">mode</span><span class="p">:</span> <span class="kt">UIDatePicker</span><span class="o">.</span><span class="kt">Mode</span><span class="p">,</span>
<span class="nv">date</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">selectedDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">maximumDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">minimumDate</span><span class="p">:</span> <span class="kt">Date</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">,</span>
<span class="nv">selectionAction</span><span class="p">:</span> <span class="kt"><a href="../Typealiases.html#/s:17RNAlertController21AlertDatePickerActiona">AlertDatePickerAction</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">RNAlertController</span></code></pre>

</div>
Expand All @@ -759,7 +761,7 @@ <h4>Parameters</h4>
<tr>
<td>
<code>
<em>date</em>
<em>selectedDate</em>
</code>
</td>
<td>
Expand All @@ -768,6 +770,30 @@ <h4>Parameters</h4>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>maximumDate</em>
</code>
</td>
<td>
<div>
<p>Maximum date that a date picker can show.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>minimumDate</em>
</code>
</td>
<td>
<div>
<p>Minimum date that a date picker can show.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
Expand Down
Loading

0 comments on commit 6852845

Please sign in to comment.