MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / getDrawParams

Function getDrawParams

packages/core/ui/styling/background.ios.ts:495–610  ·  view source on GitHub ↗
(this: void, image: UIImage, background: BackgroundDefinition, width: number, height: number)

Source from the content-addressed store, hash-verified

493}
494
495function getDrawParams(this: void, image: UIImage, background: BackgroundDefinition, width: number, height: number): BackgroundDrawParams {
496 if (!image) {
497 return null;
498 }
499
500 const res: BackgroundDrawParams = {
501 repeatX: true,
502 repeatY: true,
503 posX: 0,
504 posY: 0,
505 };
506
507 // repeat
508 if (background.repeat) {
509 switch (background.repeat.toLowerCase()) {
510 case 'no-repeat':
511 res.repeatX = false;
512 res.repeatY = false;
513 break;
514
515 case 'repeat-x':
516 res.repeatY = false;
517 break;
518
519 case 'repeat-y':
520 res.repeatX = false;
521 break;
522 }
523 }
524
525 const imageSize = image.size;
526 let imageWidth = imageSize.width;
527 let imageHeight = imageSize.height;
528
529 // size
530 const size = background.size;
531 if (size) {
532 const values = cssParse(size);
533 if (values.length === 2) {
534 const vx = values[0] as CSSValue;
535 const vy = values[1] as CSSValue;
536 if (vx.unit === '%' && vy.unit === '%') {
537 imageWidth = (width * vx.value) / 100;
538 imageHeight = (height * vy.value) / 100;
539
540 res.sizeX = imageWidth;
541 res.sizeY = imageHeight;
542 } else if (vx.type === 'number' && vy.type === 'number' && ((vx.unit === 'px' && vy.unit === 'px') || (vx.unit === '' && vy.unit === ''))) {
543 imageWidth = vx.value;
544 imageHeight = vy.value;
545
546 res.sizeX = imageWidth;
547 res.sizeY = imageHeight;
548 }
549 } else if (values.length === 1 && values[0].type === 'ident') {
550 let scale = 0;
551 if (values[0].string === 'cover') {
552 scale = Math.max(width / imageWidth, height / imageHeight);

Callers 1

generatePatternImageFunction · 0.85

Calls 1

parsePositionFunction · 0.85

Tested by

no test coverage detected