AttributeModifier.ets 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import StyleConstants from '../constants/StyleConstants'
  2. export class BackgroundPageModifier implements AttributeModifier<CommonAttribute> {
  3. isNeedImage: boolean
  4. isNeedPaddingTop: boolean
  5. isNeedPaddingBottom: boolean
  6. constructor(isNeedImage: boolean, isNeedPaddingTop: boolean = true, isNeedPaddingBottom: boolean = true) {
  7. this.isNeedImage = isNeedImage
  8. this.isNeedPaddingTop = isNeedPaddingTop
  9. this.isNeedPaddingBottom = isNeedPaddingBottom
  10. }
  11. applyNormalAttribute(instance: CommonAttribute): void {
  12. if (this.isNeedImage) {
  13. instance
  14. .height(StyleConstants.FULL_PARENT)
  15. .width(StyleConstants.FULL_PARENT)
  16. .backgroundColor($r("app.color.theme_bg_color"))
  17. // .backgroundImage($r("app.media.bgPage"))
  18. .backgroundImageSize({ width: '100%', height: '100%' })//backgroundImageSize((ImageSize.Cover))
  19. .backgroundImagePosition(Alignment.Center)
  20. .padding({
  21. top: this.isNeedPaddingTop ? StyleConstants.TOP_HEIGHT : 0,
  22. bottom: this.isNeedPaddingBottom ? StyleConstants.BOTTOM_HEIGHT : 0,
  23. left: 10,
  24. right: 10
  25. })
  26. } else {
  27. instance
  28. .height(StyleConstants.FULL_PARENT)
  29. .width(StyleConstants.FULL_PARENT)
  30. .backgroundColor($r("app.color.theme_bg_color"))
  31. .padding({
  32. top: this.isNeedPaddingTop ? StyleConstants.TOP_HEIGHT : 0,
  33. bottom: this.isNeedPaddingBottom ? StyleConstants.BOTTOM_HEIGHT : 0,
  34. left: 10,
  35. right: 10
  36. })
  37. }
  38. }
  39. }