TkStartAdComp.ets 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { BuildATSplashAdView } from 'anythink_sdk'
  2. import { windowHelper } from '../../../utils/arkts/utils/WindowHelper'
  3. import { tkStartAd, TkStartAd } from '../utils/TkStartAd'
  4. @Component
  5. export struct TkStartAdComp {
  6. @BuilderParam @Require placeholderComponent: () => void
  7. @State private tkStartAd: TkStartAd = tkStartAd
  8. @State private isLoaded: boolean = false
  9. aboutToAppear(): void {
  10. const id = setTimeout(() => {
  11. this.tkStartAd.showAd = false
  12. }, 5000)
  13. this.tkStartAd.loadedCallBack = () => {
  14. if (this.tkStartAd.splashAd.isAdReady()) {
  15. this.isLoaded = true
  16. }
  17. clearTimeout(id)
  18. }
  19. this.tkStartAd.onAdClosed = () => {
  20. this.tkStartAd.showAd = false
  21. }
  22. }
  23. build() {
  24. if (this.tkStartAd.showAd) {
  25. Stack() {
  26. Column() {
  27. this.placeholderComponent()
  28. }
  29. .width('100%')
  30. .height('100%')
  31. .backgroundColor(Color.White)
  32. .justifyContent(FlexAlign.Center)
  33. if (this.isLoaded) {
  34. BuildATSplashAdView(this.tkStartAd.splashAd, { windowStage: windowHelper.windowStage })
  35. }
  36. }
  37. }
  38. }
  39. }