@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
59 lines • 2.68 kB
JavaScript
import { supportsGlass } from '../../../utils/constants';
import { iosGlassEffectProperty } from '../../core/view';
import { LiquidGlassCommon } from './liquid-glass-common';
export class LiquidGlass extends LiquidGlassCommon {
createNativeView() {
// Use UIVisualEffectView as the root so interactive effects can track touches
const effect = UIGlassEffect.effectWithStyle(1 /* UIGlassEffectStyle.Clear */);
effect.interactive = true;
const effectView = UIVisualEffectView.alloc().initWithEffect(effect);
effectView.frame = CGRectMake(0, 0, 0, 0);
effectView.autoresizingMask = 2 /* UIViewAutoresizing.FlexibleWidth */ | 16 /* UIViewAutoresizing.FlexibleHeight */;
effectView.clipsToBounds = true;
// Host for all children so parent layout works as usual
const host = UIView.new();
host.frame = effectView.bounds;
host.autoresizingMask = 2 /* UIViewAutoresizing.FlexibleWidth */ | 16 /* UIViewAutoresizing.FlexibleHeight */;
host.userInteractionEnabled = true;
effectView.contentView.addSubview(host);
this._contentHost = host;
return effectView;
}
_addViewToNativeVisualTree(child, atIndex) {
const parentNativeView = this._contentHost;
const childNativeView = child.nativeViewProtected;
if (parentNativeView && childNativeView) {
if (typeof atIndex !== 'number' || atIndex >= parentNativeView.subviews.count) {
parentNativeView.addSubview(childNativeView);
}
else {
parentNativeView.insertSubviewAtIndex(childNativeView, atIndex);
}
// If the child has an outer shadow layer, ensure it is attached under the child's layer
if (childNativeView.outerShadowContainerLayer && !childNativeView.outerShadowContainerLayer.superlayer) {
this.nativeViewProtected.layer.insertSublayerBelow(childNativeView.outerShadowContainerLayer, childNativeView.layer);
}
return true;
}
return false;
}
[iosGlassEffectProperty.setNative](value) {
this._applyGlassEffect(value, {
effectType: 'glass',
targetView: this.nativeViewProtected,
toGlassStyleFn: toUIGlassStyle,
});
}
}
export function toUIGlassStyle(value) {
if (supportsGlass()) {
switch (value) {
case 'regular':
return 0 /* UIGlassEffectStyle?.Regular */ ?? 0;
case 'clear':
return 1 /* UIGlassEffectStyle?.Clear */ ?? 1;
}
}
return 1;
}
//# sourceMappingURL=index.ios.js.map