-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VisionOS events and entities (#857)
* Add new VisionOS classes * Add tests * Update demo * Standardise ID capitalisation * Automatically track window group entity with OpenWindow and DismissWindow events * Make string IDs the main property * Add ImmersiveSpaceStateMachine * Update demo app * Update following merge * Add immersive space entity to open event when autotracking is off * Small review changes * Always update state on open event * Correct visionOS capitalisation * Add immersive space entity by default * Generate viewId UUID for immersive space
- Loading branch information
1 parent
e579b0c
commit 17c8167
Showing
19 changed files
with
1,104 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
class ImmersiveSpaceState: State { | ||
var dismissEventTracked = false | ||
|
||
var id: String | ||
var viewId: UUID? | ||
var immersionStyle: ImmersionStyle? | ||
var upperLimbVisibility: UpperLimbVisibility? | ||
|
||
init(id: String, viewId: UUID? = nil, immersionStyle: ImmersionStyle? = nil, upperLimbVisibility: UpperLimbVisibility? = nil) { | ||
self.id = id | ||
self.viewId = viewId | ||
self.immersionStyle = immersionStyle | ||
self.upperLimbVisibility = upperLimbVisibility | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
Sources/Core/StateMachine/ImmersiveSpaceStateMachine.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,107 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
class ImmersiveSpaceStateMachine: StateMachineProtocol { | ||
|
||
static var identifier: String { return "ImmersiveSpace" } | ||
var identifier: String { return ImmersiveSpaceStateMachine.identifier } | ||
|
||
var subscribedEventSchemasForEventsBefore: [String] { | ||
return [] | ||
} | ||
|
||
var subscribedEventSchemasForTransitions: [String] { | ||
return [swiftuiOpenImmersiveSpaceSchema, swiftuiDismissImmersiveSpaceSchema] | ||
} | ||
|
||
var subscribedEventSchemasForEntitiesGeneration: [String] { | ||
return ["*"] | ||
} | ||
|
||
var subscribedEventSchemasForPayloadUpdating: [String] { | ||
return [] | ||
} | ||
|
||
var subscribedEventSchemasForAfterTrackCallback: [String] { | ||
return [] | ||
} | ||
|
||
var subscribedEventSchemasForFiltering: [String] { | ||
return [] | ||
} | ||
|
||
func eventsBefore(event: Event) -> [Event]? { | ||
return nil | ||
} | ||
|
||
func transition(from event: Event, state: State?) -> State? { | ||
if let e = event as? OpenImmersiveSpaceEvent { | ||
return ImmersiveSpaceState( | ||
id: e.id, | ||
viewId: e.viewId, | ||
immersionStyle: e.immersionStyle, | ||
upperLimbVisibility: e.upperLimbVisibility | ||
) | ||
} else { | ||
if let s = state as? ImmersiveSpaceState { | ||
if s.dismissEventTracked { | ||
return nil | ||
} | ||
// state persists for the first Dismiss event after an Open | ||
let currentState = ImmersiveSpaceState( | ||
id: s.id, | ||
viewId: s.viewId, | ||
immersionStyle: s.immersionStyle, | ||
upperLimbVisibility: s.upperLimbVisibility | ||
) | ||
currentState.dismissEventTracked = true | ||
return currentState | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func entities(from event: InspectableEvent, state: State?) -> [SelfDescribingJson]? { | ||
// the open event already has the entity | ||
if event.schema == swiftuiOpenImmersiveSpaceSchema { | ||
return nil | ||
} | ||
|
||
if let s = state as? ImmersiveSpaceState { | ||
if s.dismissEventTracked == true && event.schema != swiftuiDismissImmersiveSpaceSchema { | ||
return nil | ||
} | ||
let entity = ImmersiveSpaceEntity( | ||
id: s.id, | ||
viewId: s.viewId, | ||
immersionStyle: s.immersionStyle, | ||
upperLimbVisibility: s.upperLimbVisibility | ||
) | ||
return [entity] | ||
} | ||
return nil | ||
} | ||
|
||
func payloadValues(from event: InspectableEvent, state: State?) -> [String : Any]? { | ||
return nil | ||
} | ||
|
||
func afterTrack(event: InspectableEvent) { | ||
} | ||
|
||
func filter(event: InspectableEvent, state: State?) -> Bool? { | ||
return nil | ||
} | ||
} |
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
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.