How to implement dynamic type with collection view compositional layout?

Hi.
To support dynamic type in the collection view, in the book we create a custom collection view layout.
I have a question. Can we use the collection view compositional layout and still support the dynamic type?

Currently, I use the collection view compositional layout for my company project and try to use traitCollectionDidChange(_:) to update the layout by deactivating and activate a set of constraints in the custom collection view cell and call the collectionView.collectionViewLayout.invalidateLayout() in the view controller.

The problem is when the user changes the dynamic type in the settings, sometimes the cell change layout correctly but sometimes doesn’t. if the user scrolls the collection view most of the new cell display correctly. Not sure if I have to use a custom collection view layout instead of a collection view compositional layout.

Thanks