Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): support API directive queries #290

Merged
merged 1 commit into from
May 24, 2017
Merged

Conversation

ThomasBurleson
Copy link
Contributor

@ThomasBurleson ThomasBurleson commented May 19, 2017

  • support DI of flexbox/api Directive classes
  • implement Directive method activatedValue getter/setter
    • to imperatively read current activated input value
    • to write API values with immediate style updates
  • implement demo using splitters (ngxSplit) with fxLayout and fxFlex layouts

Based on issues and ideas by @amcdnl + ngx-u

Fixes #266.

@ThomasBurleson
Copy link
Contributor Author

ThomasBurleson commented May 19, 2017

Snapshot of Splitter Demo

screen shot 2017-05-18 at 7 19 36 pm

issue.266.demo.ts

<div fxLayout="row" style="height:500px" ngxSplit="row">
  <div fxFlex="30%" ngxSplitArea class="c1r1" > </div>

  <div class="handle handle-row" ngxSplitHandle>
      <i class="material-icons">&#xE25D;</i>
  </div>
  
  <div fxFlex="70%" ngxSplitArea>
    <div fxLayout="column" fxFlexFill ngxSplit="column">
      <div fxFlex="50%" ngxSplitArea class="c2r1_body" > </div>
      
      <div class="handle handle-column" ngxSplitHandle>
          <i class="material-icons">&#xE25D;</i>
      </div>
      
      <div fxFlex="50%" ngxSplitArea class="c2r2" > </div>
    </div>
  </div>
</div>

split.directive.ts

  onDrag({x, y}): void {
    const dragAmount = (this.direction === 'row') ? x : y;

    this.areas.forEach((area, i) => {
      const flex = (area.flex as FlexDirective);
      const delta = (i === 0) ? dragAmount : -dragAmount;
      const currentValue = flex.activatedValue;        

      // Update Flex-Layout value to build/inject new flexbox CSS
      flex.activatedValue = this.calculateSize(currentValue, delta);
    });
  }

@amcdnl - would you mind reviewing ?

@ThomasBurleson ThomasBurleson force-pushed the thomas/issue-266 branch 3 times, most recently from 3aaf0e0 to b8a5852 Compare May 19, 2017 11:48
@ThomasBurleson
Copy link
Contributor Author

@kara - please review.

@amcdnl
Copy link
Contributor

amcdnl commented May 19, 2017

@ThomasBurleson - This looks awesome!

@ThomasBurleson
Copy link
Contributor Author

@jelbourn - please presubmit.

@jelbourn
Copy link
Member


let activatedKey = this._mqActivation.activatedInputKey;
this._inputMap[activatedKey] = value;
this._updateStyle(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic can be simplified:

if (this._mqActivation) {
  this._inputMap[this._mqActivation.activatedInputKey] = value;
} 
this._updateStyle(value);

@@ -65,10 +91,17 @@ export abstract class BaseFxDirective implements OnDestroy {
// *********************************************

/**
* Abstract method...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs documentation, also should it throw an error that it needs to be implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for drawing my attention to this. This was only a partial (in fact poor) solution.
I found another more robust approach.

value = value || 'row';
this._applyStyleToElements(buildLayoutCSS(value), [target]);
}
let value = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: single quotes

return direction || styles[key];
}, null);

let immediateValue = findDirection(target['style']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this instead of target.style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot recall the reasoning. Will fix.

}, null);

let immediateValue = findDirection(target['style']);
value = immediateValue || findDirection(getComputedStyle(target as Element));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason that target isn't an Element in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this._elementRef.nativeElement is typed as any... so I cast here to document explicitly.


return value ? value.trim() : "row";
return value ? value.trim() : "row";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: single quotes

@@ -126,15 +128,15 @@ describe('flex directive', () => {
`);
fixture.detectChanges();
let element = queryFor(fixture, "[fxFlex]")[0].nativeElement;
let parent = queryFor(fixture, ".test")[0].nativeElement;
let parent = queryFor(fixture, ".test")[0].nativeElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single quotes

@@ -149,11 +151,11 @@ describe('flex directive', () => {
`);
fixture.detectChanges();
let element = queryFor(fixture, "[fxFlex]")[0].nativeElement;
let parent = queryFor(fixture, ".parent")[0].nativeElement;
let parent = queryFor(fixture, ".parent")[0].nativeElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single quotes

@@ -65,10 +91,17 @@ export abstract class BaseFxDirective implements OnDestroy {
// *********************************************

/**
* Abstract method...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally deleted Miles comments: docs needed and throw exception if not overriden


let activatedKey = this._mqActivation.activatedInputKey;
this._inputMap[activatedKey] = value;
this._updateStyle(value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidently deleted @mmalerba comments. Refactor ing

return direction || styles[key];
}, null);

let immediateValue = findDirection(target['style']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot recall the reasoning. Will fix.

}, null);

let immediateValue = findDirection(target['style']);
value = immediateValue || findDirection(getComputedStyle(target as Element));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this._elementRef.nativeElement is typed as any... so I cast here to document explicitly.

@@ -65,10 +91,17 @@ export abstract class BaseFxDirective implements OnDestroy {
// *********************************************

/**
* Abstract method...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for drawing my attention to this. This was only a partial (in fact poor) solution.
I found another more robust approach.

@ThomasBurleson
Copy link
Contributor Author

@mmalerba - updated with all your suggested changes. set activatedInput(value) now triggers ngOnChanges(); see https://github.com/angular/flex-layout/pull/290/files#diff-abac303936dc314fed0f18d5429ac42f

* support DI of flexbox/api Directive classes
* implement Directive method `activatedValue` getter/setter
  * to imperatively read current activated input value
  * to write API values with immediate style updates
* implement demo using splitters (ngxSplit) with fxLayout and fxFlex layouts
@mmalerba mmalerba added the pr: lgtm This PR has been approved by the reviewer label May 24, 2017
@tinayuangao tinayuangao merged commit f5558de into master May 24, 2017
@ThomasBurleson ThomasBurleson deleted the thomas/issue-266 branch August 7, 2017 22:36
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes pr: lgtm This PR has been approved by the reviewer pr: needs presubmit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose fxFlex directive class to access via ContentChildren
6 participants