ios – Resize RCTView and reflow the dad or mum view structure


I am engaged on a react native wrapper to a third social gathering library.
I have to show a view that can show a picture that’s loaded by way of the third social gathering library.
So i first add a subclass of RCTView within the view hierarchy, begin loading the picture and when the picture is loaded I resize the view to show the picture with no cropping or padding.

The problem i am operating into is that I can resize my subclass of RCTView and that works tremendous, however different factor round my view will not be relayed out, so my view find yourself behind the view that’s under it…

Right here is the screenshot, the white half within the center ought to be taller to show the complete picture.
enter image description here

The essential a part of the code

class EquativDisplayView: ExpoView {
let container = UIView()
var bannerView:SASBannerView?

required init(appContext: AppContext? = nil) {
    tremendous.init(appContext: appContext)
    clipsToBounds = true
    addSubview(container)
}

override func layoutSubviews() {
    //ensure all of the view hold the identical measurement
    container.body = bounds
    bannerView?.body = bounds
}

func setConfiguration(_ configuration: Configuration) {
    //load the picture
    let bannerView = SASBannerView(body: CGRect(x: 0, y: 0, width: bounds.width, peak: 0))

    let adPlacement = SASAdPlacement.init(testAd: SASAdPlacementTest(rawValue:  testPlacementId) ?? .bannerMRAID)
    bannerView.load(with: adPlacement)
    
    bannerView.delegate = self
    
    // Including the banner view to the present view controller
    container.addSubview(bannerView)
    self.bannerView = bannerView
}
}


extension EquativDisplayView :SASBannerViewDelegate
{
func bannerView(_ bannerView: SASBannerView, didDownloadAd advert: SASAd) {
    
    print("advert did load")
    let optimalHeight = bannerView.optimalAdViewHeight(forContainer: nil)
    let newFrame = CGRect(x: body.origin.x,
                          y: body.origin.y,
                          width: body.measurement.width,
                          peak: optimalHeight)
    body = newFrame
    print("resizing %@", newFrame)
    setNeedsLayout()
    superview!.setNeedsLayout()      < ============ at this level I am anticipating the display structure to get up to date, however i am clearly lacking one thing
}
}

the react native aspect

export default perform App() {
  return (
    <View type={types.container}>
      <View type={{ peak: 100 }} />
      <Textual content type={{ flex: 1, backgroundColor: "yellow", width: "100%", textAlign: "middle" }}>
        {EquativDisplay.good day()}
      </Textual content>
      <EquativDisplay.EquativDisplayView
        type={{
          width: "100%",
          padding: 10,
          backgroundColor: "inexperienced",
        }}
        configuration={{
          testPlacementId: EquativDisplay.PlacementTest.BannerMRAID,
        }}
      />
      <Textual content type={{ flex: 1, backgroundColor: "yellow", width: "100%", textAlign: "middle" }}>
        {EquativDisplay.good day()}
      </Textual content>
    </View>
  )
}

The output from the logs:

layoutSubviews %@ (0.0, 0.0, 393.0, 20.0)
advert did load
resizing %@ (0.0, 466.0, 393.0, 61.0)
layoutSubviews %@ (0.0, 0.0, 393.0, 61.0)

The peak ought to be 61 which is appropriate, the underside yellow view ought to be resized, however is just not.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles