Skip to content

Commit

Permalink
Introduce enhanced enums with instance variables and generative const…
Browse files Browse the repository at this point in the history
…ructors
  • Loading branch information
droibit committed Sep 12, 2023
1 parent 095b1bb commit a976f33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class CustomTabsAnimation {
/// Exit animation for the custom tab.
final String? endExit;

@internal
Map<String, String> toMap() {
final dest = <String, String>{};
if (startEnter != null && startExit != null) {
Expand All @@ -133,17 +134,13 @@ class CustomTabsAnimation {
}

/// The position of the close button of Custom Tabs.
enum CustomTabsCloseButtonPosition { start, end }

extension CustomTabsCloseButtonPositionRawValue
on CustomTabsCloseButtonPosition {
@visibleForTesting
int get rawValue {
switch (this) {
case CustomTabsCloseButtonPosition.start:
return 1;
case CustomTabsCloseButtonPosition.end:
return 2;
}
}
}
enum CustomTabsCloseButtonPosition {
start(1),
end(2);

@internal
const CustomTabsCloseButtonPosition(this.rawValue);

@internal
final int rawValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,16 @@ class SafariViewControllerOptions {
///
/// * [SFSafariViewController.DismissButtonStyle](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle)
///
enum SafariViewControllerDismissButtonStyle { done, close, cancel }

extension SafariViewControllerDismissButtonStyleRawValue
on SafariViewControllerDismissButtonStyle {
@visibleForTesting
int get rawValue {
switch (this) {
case SafariViewControllerDismissButtonStyle.done:
return 0;
case SafariViewControllerDismissButtonStyle.close:
return 1;
case SafariViewControllerDismissButtonStyle.cancel:
return 2;
}
}
enum SafariViewControllerDismissButtonStyle {
done(0),
close(1),
cancel(2);

@internal
const SafariViewControllerDismissButtonStyle(this.rawValue);

@internal
final int rawValue;
}

/// A view presentation style in which the presented view covers the screen.
Expand All @@ -106,41 +101,26 @@ extension SafariViewControllerDismissButtonStyleRawValue
enum ViewControllerModalPresentationStyle {
/// The default presentation style chosen by the system.
/// - Availability: iOS13.0+
automatic,
automatic(-2),

/// A presentation style that indicates no adaptations should be made.
none,
none(-1),

/// A presentation style in which the presented view covers the screen.
fullScreen,
fullScreen(0),

/// A presentation style that partially covers the underlying content.
pageSheet,
pageSheet(1),

/// A presentation style that displays the content centered in the screen.
formSheet,
formSheet(2),

/// A view presentation style in which the presented view covers the screen.
overFullScreen
}
overFullScreen(5);

extension ViewControllerModalPresentationStyleRawValue
on ViewControllerModalPresentationStyle {
@visibleForTesting
int get rawValue {
switch (this) {
case ViewControllerModalPresentationStyle.automatic:
return -2;
case ViewControllerModalPresentationStyle.none:
return -1;
case ViewControllerModalPresentationStyle.fullScreen:
return 0;
case ViewControllerModalPresentationStyle.pageSheet:
return 1;
case ViewControllerModalPresentationStyle.formSheet:
return 2;
case ViewControllerModalPresentationStyle.overFullScreen:
return 5;
}
}
}
@internal
const ViewControllerModalPresentationStyle(this.rawValue);

@internal
final int rawValue;
}

0 comments on commit a976f33

Please sign in to comment.