Block off AppKit animator proxy to fix iOS compiling

This commit is contained in:
Ryan McGrath 2022-08-17 16:01:58 -07:00 committed by Sebastian Imlay
parent e8f954080b
commit 8b43d43caf
3 changed files with 26 additions and 7 deletions

View file

@ -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,
}
}

View file

@ -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")]

View file

@ -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<T = ()> {
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<T = ()> {
/// 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<T> View<T>
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<T> View<T> {
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<T> View<T> {
center_x: self.center_x.clone(),
#[cfg(feature = "autolayout")]
center_y: self.center_y.clone()
center_y: self.center_y.clone(),
}
}