From 8b43d43caf0640e49dbcb724c0337b670f293f70 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 17 Aug 2022 16:01:58 -0700 Subject: [PATCH] Block off AppKit animator proxy to fix iOS compiling --- src/layout/constraint.rs | 13 ++++++++++--- src/layout/mod.rs | 3 +++ src/view/mod.rs | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/layout/constraint.rs b/src/layout/constraint.rs index 1353239..91ecda9 100644 --- a/src/layout/constraint.rs +++ b/src/layout/constraint.rs @@ -10,6 +10,7 @@ use objc_id::ShareId; use crate::foundation::{id, NO, YES}; +#[cfg(all(feature = "appkit", target_os = "macos"))] use super::LayoutConstraintAnimatorProxy; /// A wrapper for `NSLayoutConstraint`. This both acts as a central path through which to activate @@ -31,18 +32,22 @@ pub struct LayoutConstraint { pub priority: f64, /// An animator proxy that can be used inside animation contexts. - pub animator: LayoutConstraintAnimatorProxy + /// This is currently only supported on macOS with the `appkit` feature. + #[cfg(all(feature = "appkit", target_os = "macos"))] + pub animator: LayoutConstraintAnimatorProxy, } impl LayoutConstraint { /// An internal method for wrapping existing constraints. pub(crate) fn new(object: id) -> Self { LayoutConstraint { + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: LayoutConstraintAnimatorProxy::new(object), + constraint: unsafe { ShareId::from_ptr(object) }, offset: 0.0, multiplier: 0.0, - priority: 0.0 + priority: 0.0, } } @@ -55,11 +60,13 @@ impl LayoutConstraint { } LayoutConstraint { + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: self.animator, + constraint: self.constraint, offset: offset, multiplier: self.multiplier, - priority: self.priority + priority: self.priority, } } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 62d0392..38bafee 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -6,7 +6,10 @@ mod traits; pub use traits::Layout; +#[cfg(all(feature = "appkit", target_os = "macos"))] mod animator; + +#[cfg(all(feature = "appkit", target_os = "macos"))] pub use animator::LayoutConstraintAnimatorProxy; #[cfg(feature = "autolayout")] diff --git a/src/view/mod.rs b/src/view/mod.rs index cc75c0e..98c9466 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -58,7 +58,10 @@ use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY, SafeAre #[cfg(feature = "appkit")] use crate::pasteboard::PasteboardType; +#[cfg(all(feature = "appkit", target_os = "macos"))] mod animator; + +#[cfg(all(feature = "appkit", target_os = "macos"))] pub use animator::ViewAnimatorProxy; #[cfg_attr(feature = "appkit", path = "appkit.rs")] @@ -94,6 +97,9 @@ pub struct View { pub objc: ObjcProperty, /// An object that supports limited animations. Can be cloned into animation closures. + /// + /// This is currently only supported on macOS with the `appkit` feature. + #[cfg(all(feature = "appkit", target_os = "macos"))] pub animator: ViewAnimatorProxy, /// References the underlying layer. This is consistent across AppKit & UIKit - in AppKit @@ -145,7 +151,7 @@ pub struct View { /// A pointer to the Objective-C runtime center Y layout constraint. #[cfg(feature = "autolayout")] - pub center_y: LayoutAnchorY + pub center_y: LayoutAnchorY, } impl Default for View { @@ -209,8 +215,9 @@ impl View { layer: Layer::wrap(unsafe { msg_send![view, layer] }), + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: ViewAnimatorProxy::new(view), - objc: ObjcProperty::retain(view) + objc: ObjcProperty::retain(view), } } @@ -222,7 +229,7 @@ impl View { impl View where - T: ViewDelegate + 'static + T: ViewDelegate + 'static, { /// Initializes a new View with a given `ViewDelegate`. This enables you to respond to events /// and customize the view as a module, similar to class-based systems. @@ -256,6 +263,8 @@ impl View { is_handle: true, layer: self.layer.clone(), objc: self.objc.clone(), + + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: self.animator.clone(), #[cfg(feature = "autolayout")] @@ -289,7 +298,7 @@ impl View { center_x: self.center_x.clone(), #[cfg(feature = "autolayout")] - center_y: self.center_y.clone() + center_y: self.center_y.clone(), } }