JoshDSommer / nativescript-ngx-shadow

Angular directive to apply shadows to native elements according to the elevation level guidelines of material design specification
Apache License 2.0
9 stars 6 forks source link

(WIP) Add fix for iOS layout shadow wrapper #22

Open jalbatross opened 4 years ago

jalbatross commented 4 years ago

For layouts which use the position of the child element in the layout structure as the element's position (StackLayout, for example), the plugin works fine. However, for layouts where child node position may not have any correlation to the element's rendered UI (GridLayout, AbsoluteLayout, etc.), you end up running into problems.

For example, take the following layout on iOS:

<GridLayout rows="auto auto auto">
  <Label text="0" row="0"></Label>
  <Label text="1" row="1" shadow="10"></Label>
  <Label text="2" row="2"></Label>
</GridLayout>

Under the hood, this happens:

<GridLayout rows="auto auto auto">
  <Label text="0" row="0"></Label>
  <StackLayout>
    <Label text="1" row="1" shadow="10"></Label>
  </StackLayout>
  <Label text="2" row="2"></Label>
</GridLayout>

So the second label does not render correctly.

Currently this PR just applies the row, column, rowSpan, and colSpan attributes to the wrapping StackLayout if the original element is wrapped in a GridLayout.

More work needs to be done so that the wrapping StackLayout gets the correct attributes from the original element in order to render in the view correctly for all layouts - I believe #17 was caused by a similar issue for AbsoluteLayouts.

As-is, this is mergeable but does not account for all possible use cases.

edusperoni commented 4 years ago

Please change your array to a Set and also bind property change event (remember to clean them up afterward!)

parent.on(Observable.propertyChangeEvent, (propertyChangeData: PropertyChangeData) => {
    if(propertySet.has(propertyChangeData.propertyName)) {
        this.wrapper[propertyChangeData.propertyName] = propertyChangeData.value;
    }
});

To clean it up you should probably move that anonymous function to a named function and call: parent.on(Observable.propertyChangeEvent, this.myfunction, this);

and clean up with: parent.off(Observable.propertyChangeEvent, this.myfunction,this);