diff --git a/src/feedback.common.ts b/src/feedback.common.ts index 1493a8e..ec365b1 100644 --- a/src/feedback.common.ts +++ b/src/feedback.common.ts @@ -67,6 +67,15 @@ export interface FeedbackShowOptions { * Default depends on the 'type' property. */ backgroundColor?: Color; + /** + * Use gradient as background color. When this is used it overrides any 'backgroundColor' that is set. + * Default depends on the 'type' property. + */ + gradientColors?: Array; + /** + * The direction the gradient colors should span. + */ + gradientDirection?: 'left' | 'right' | 'up' | 'down'; /** * A resource like 'customimage' which refers to: * - iOS: App_Resources/customimage.png (and customimage@2x.png / customimage@3x.png) diff --git a/src/feedback.ios.ts b/src/feedback.ios.ts index b8adaea..2bff2ca 100644 --- a/src/feedback.ios.ts +++ b/src/feedback.ios.ts @@ -29,7 +29,35 @@ export class Feedback extends FeedbackCommon { Feedback.getType(options.type), Feedback.getPosition(options.position)); - if (options.backgroundColor) { + if (options.gradientColors) { + message.alertViewBackgroundColor = UIColor.clearColor; + + const layerGradient = CAGradientLayer.layer(); + layerGradient.colors = NSArray.arrayWithArray(options.gradientColors.map(c => c.ios.CGColor)); + + const gradientDirection = options.gradientDirection || 'down'; + switch (gradientDirection) { + case 'up': + layerGradient.startPoint = CGPointMake(.5, 1); + layerGradient.endPoint = CGPointMake(.5, 0); + break; + case 'left': + layerGradient.startPoint = CGPointMake(.5, 0); + layerGradient.endPoint = CGPointMake(.5, 1); + break; + case 'right': + layerGradient.startPoint = CGPointMake(0, .5); + layerGradient.endPoint = CGPointMake(1, .5); + break; + default: + layerGradient.startPoint = CGPointMake(.5, 0); + layerGradient.endPoint = CGPointMake(.5, 1); + break; + } + layerGradient.frame = message.view.bounds; + + message.view.layer.insertSublayerAtIndex(layerGradient, 0); + } else if (options.backgroundColor) { message.alertViewBackgroundColor = options.backgroundColor.ios; }