-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: * `RNIModalPresentationState` - Remove "focus"-related states. * Impl: Add `RNIModalFocusState`. * `RNIModal` - Refactor: Replace `RNIModalState.isModalInFocus` w/ `modalFocusState`, and update usage.
- Loading branch information
1 parent
891eef9
commit 7817414
Showing
6 changed files
with
112 additions
and
30 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
93 changes: 93 additions & 0 deletions
93
ios/src_library/React Native/RNIModal/RNIModalFocusState.swift
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,93 @@ | ||
// | ||
// RNIModalFocusState.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/8/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public enum RNIModalFocusState: String { | ||
case INITIAL; | ||
|
||
case FOCUSING | ||
case FOCUSED; | ||
|
||
case BLURRING; | ||
case BLURRED; | ||
|
||
// MARK: - Properties - Computed | ||
// ----------------------------- | ||
|
||
public var isInitialized: Bool { | ||
self != .INITIAL | ||
}; | ||
|
||
public var isFocused: Bool { | ||
self == .FOCUSED; | ||
}; | ||
|
||
public var isBlurred: Bool { | ||
self == .BLURRED || self == .INITIAL; | ||
}; | ||
|
||
public var isFocusing: Bool { | ||
self == .FOCUSING; | ||
}; | ||
|
||
public var isBlurring: Bool { | ||
self == .BLURRING; | ||
}; | ||
|
||
public var isTransitioning: Bool { | ||
self.isBlurring || self.isFocusing; | ||
}; | ||
|
||
public var isBlurredOrBlurring: Bool { | ||
self.isBlurred || self.isBlurring; | ||
}; | ||
|
||
public var isFocusedOrFocusing: Bool { | ||
self.isFocused || self.isFocusing; | ||
}; | ||
}; | ||
|
||
public struct RNIModalFocusStateMachine { | ||
|
||
// MARK: - Properties | ||
// ------------------ | ||
|
||
private(set) public var state: RNIModalFocusState = .INITIAL; | ||
private(set) public var statePrev: RNIModalFocusState = .INITIAL; | ||
|
||
// MARK: - Functions | ||
// ------------------ | ||
|
||
public mutating func set(state nextState: RNIModalFocusState){ | ||
let prevState = self.state; | ||
|
||
// early exit if no change | ||
guard prevState != nextState else { | ||
#if DEBUG | ||
print( | ||
"Error - RNIModalFocusStateMachine.set" | ||
+ " - arg nextState: \(nextState)" | ||
+ " - prevState: \(prevState)" | ||
+ " - No changes, ignoring..." | ||
); | ||
#endif | ||
return; | ||
}; | ||
|
||
if prevState.isInitialized && !nextState.isInitialized { | ||
/// Going from "initialized state" (e.g. `FOCUSED`, `FOCUSING`, etc), to | ||
/// an "uninitialized state" (i.e. `INITIAL`) is not allowed | ||
return; | ||
|
||
} else { | ||
self.state = nextState; | ||
self.statePrev = prevState; | ||
}; | ||
}; | ||
}; |
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