Skip to content

Commit

Permalink
feat: alpha.0
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Feb 6, 2023
1 parent bd170f8 commit d0e8a21
Show file tree
Hide file tree
Showing 125 changed files with 4,381 additions and 2,281 deletions.
44 changes: 20 additions & 24 deletions apps/demo/src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@
}
}

/*
.wrapper-5 {
display: grid;
grid-gap: 10px;
grid-template-columns: 100px 100px 100px;
grid-gap: 10;
grid-template-columns: 100 100 100;
background-color: #fff;
color: #444;

Expand All @@ -66,30 +65,27 @@
color: #fff;
border-radius: 5px;
padding: 20px;
// font-size: 150%;
.a {
grid-column: 1 / 3;
grid-row: 1;
}
.b {
grid-column: 3 ;
grid-row: 1 / 3;
}
.c {
grid-column: 1 ;
grid-row: 2 ;
}
.d {
grid-column: 2;
grid-row: 2;
}
// font-size: 150%;

&.a {
grid-column: 1 / 3;
grid-row: 1;
}
&.b {
grid-column: 3;
grid-row: 1 / 3;
}
&.c {
grid-column: 1;
grid-row: 2;
}
&.d {
grid-column: 2;
grid-row: 2;
}
}
}

*/

.wrapper-6 {
display: grid;
background: no-repeat url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/grid.png);
Expand Down
61 changes: 34 additions & 27 deletions apps/demo/src/plugin-demos/nativescript-masonkit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,76 @@
</Page.actionBar>


<!-- <ui:TSCView class="flex-example" color="white">
<!-- <ui:Flex class="flex-example" color="white">
<Label text="a" class="a"/>
<Label text="b" class="b"/>
</ui:TSCView> -->
</ui:Flex> -->




<!-- https://gridbyexample.com/examples/example5/ -->

<ui:TSCView class="wrapper-5">

<ui:TSCView class="box a">

<ui:Grid class="wrapper-5">

<ui:Grid class="box a">
<Label text="A" />
</ui:TSCView>
</ui:Grid>

<ui:TSCView class="box b">
<ui:Grid class="box b">
<Label text="B" />
</ui:TSCView>
</ui:Grid>

<ui:TSCView class="box c">
<ui:Grid class="box c">
<Label text="C" />
</ui:TSCView>
</ui:Grid>

<ui:TSCView class="box d">
<ui:Grid class="box d">
<Label text="D" />
</ui:TSCView>
</ui:TSCView>
</ui:Grid>
</ui:Grid>



<!--
https://gridbyexample.com/examples/example26/ -->


<!--
<ui:TSCView class="wrapper-6">
<ui:TSCView class="box a">

<!-- <ui:Container class="wrapper-6">
<ui:Container class="box a">
<Label text="This is box A."></Label>
<Label text="align-self: stretch"></Label>
</ui:TSCView>
</ui:Container>
<ui:TSCView class="box b">
<ui:Container class="box b">
<Label text="This is box B."></Label>
<Label text="align-self: end"></Label>
</ui:TSCView>
</ui:Container>
<ui:TSCView class="box c">
<ui:Container class="box c">
<Label text="This is box C."></Label>
<Label text="align-self: start"></Label>
</ui:TSCView>
</ui:Container>
<ui:TSCView class="box d">
<ui:Container class="box d">
<Label text="This is box D."></Label>
<Label text="align-self: center"></Label>
</ui:TSCView>
</ui:Container>
<ui:TSCView class="box e">
<ui:Container class="box e">
<Label
textWrap="true"
text="Each of the boxes on the left has a grid area of 3 columns and 3 rows (we're counting the gutter col/row). So each covers the same size area as box A."></Label>
<Label text="The align-self property is used to align the content inside the grid-area."></Label>
</ui:TSCView>
</ui:Container>
</ui:TSCView> -->
</ui:Container> -->


<!-- <ui:TSCView class="grid-example">
<!-- <ui:Grid class="grid-example">
<Label text="A" color="green" class="a" backgroundColor="red"/>
Expand All @@ -82,7 +89,7 @@
<Label text="F" class="f" backgroundColor="pink"/>
</ui:TSCView> -->
</ui:Grid> -->


<!-- <ui:TSCView id="root" flexDirection="column">
Expand Down
20 changes: 19 additions & 1 deletion packages/nativescript-masonkit/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,25 @@ export class TSCViewBase extends CustomLayoutView implements AddChildFromBuilder
}
*/

eachLayoutChild(callback: (child: View, isLast: boolean) => void): void {}
public eachLayoutChild(callback: (child: View, isLast: boolean) => void): void {
let lastChild: View = null;

this.eachChildView((cv) => {
cv._eachLayoutView((lv) => {
if (lastChild && !lastChild.isCollapsed) {
callback(lastChild, false);
}

lastChild = lv;
});

return true;
});

if (lastChild && !lastChild.isCollapsed) {
callback(lastChild, true);
}
}

public eachChild(callback: (child: ViewBase) => boolean) {
this._children.forEach((child) => {
Expand Down
105 changes: 68 additions & 37 deletions packages/nativescript-masonkit/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const enum Display {
Grid = 2,
}

const enum GridTrackRepetition {
const enum TSCGridTrackRepetition {
AutoFill = 0,

AutoFit = 1,

Count = 2,
}

const enum GridPlacementCompatType {
Expand Down Expand Up @@ -192,7 +194,7 @@ if (global.isIOS) {
try {
//@ts-ignore
const module = new global.JSIModule();
console.log(module.install());
// module.install()
// JSIEnabled = true;
} catch (error) {
console.warn('Failed to enable on FastAPI', error);
Expand Down Expand Up @@ -3360,54 +3362,70 @@ export function _parseMinMaxValue(value: string): MinMaxType {

interface GridTemplates {
is_repeating: boolean;
repeating_type: GridTrackRepetition;
repeating_type: TSCGridTrackRepetition;
repeating_count: number;
value: MinMaxType | Array<MinMaxType>;
}

const grid_templates_regex = /[^\s()]+(?:\([^\s()]+(?:\([^()]+\))?(?:, *[^\s()]+(?:\([^()]+\))?)*\))?/g;

export function _parseGridTemplates(value: string): Array<GridTemplates> {
const array = [];
if (typeof value === 'string') {
const values = value.split(') ');
const values = Array.from(value.matchAll(grid_templates_regex), (m) => m[0]);

values.forEach((item) => {
if (item.startsWith('repeat(')) {
const repeatedValues = item.replace('repeat(', '').replace(')', '').split(',');
const repeatValue = item.replace('repeat(', '').replace(')', '');

const trackEnd = repeatValue.indexOf(',');

const type = repeatedValues[0].trim();
const repetition = repeatValue.substring(0, trackEnd);

let isSingle = false;
const tracks = repeatValue
.substring(trackEnd + 1)
.split(' ')
.filter((a) => {
return a.length || a.trim() === ',';
});
let isValid = true;

let repeating_type = 0;

let repeat_count = 0;

switch (type) {
switch (repetition) {
case 'repeat-fill':
repeating_type = GridTrackRepetition.AutoFill;
repeating_type = TSCGridTrackRepetition.AutoFill;
break;
case 'repeat-fit':
repeating_type = GridTrackRepetition.AutoFit;
repeating_type = TSCGridTrackRepetition.AutoFit;
break;
default:
const number = parseInt(type);
const number = parseInt(repetition);

if (!Number.isNaN(number)) {
isSingle = true;
repeating_type = TSCGridTrackRepetition.Count;

isValid = !Number.isNaN(number);
if (isValid) {
repeat_count = number;
}

break;
}

const minMax = _parseMinMaxValue(repeatedValues[1].trim());
if (isValid) {
const tracks_array = [];
tracks.forEach((track) => {
const minMax = _parseMinMaxValue(track.trim());
tracks_array.push(minMax);
});

if (repeat_count > 0) {
for (let i = 0; i < repeat_count; i++) {
array.push({
is_repeating: !isSingle,
repeating_type,
value: minMax,
});
}
array.push({
is_repeating: true,
repeating_type,
repeating_count: repeat_count,
value: tracks_array,
});
}
} else {
const value = _parseMinMaxValue(item);
Expand Down Expand Up @@ -3440,12 +3458,15 @@ export function _setGridTemplateRows(value: Array<GridTemplates>, instance: TSCV
const tracks = Array.create('org.nativescript.mason.masonkit.MinMax', repeating.length);
let gridTrackRepetition = null;
switch (item.repeating_type) {
case GridTrackRepetition.AutoFill:
case TSCGridTrackRepetition.AutoFill:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFill;
break;
case GridTrackRepetition.AutoFit:
case TSCGridTrackRepetition.AutoFit:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFit;
break;
case TSCGridTrackRepetition.Count:
gridTrackRepetition = new org.nativescript.mason.masonkit.GridTrackRepetition.Count(item.repeating_count);
break;
}
if (gridTrackRepetition === null) {
continue;
Expand Down Expand Up @@ -3487,11 +3508,14 @@ export function _setGridTemplateRows(value: Array<GridTemplates>, instance: TSCV
const tracks = NSMutableArray.arrayWithCapacity<MinMax>(repeatingLength);
let gridTrackRepetition = null;
switch (item.repeating_type) {
case GridTrackRepetition.AutoFill:
gridTrackRepetition = GridTrackRepetition.AutoFill;
case TSCGridTrackRepetition.AutoFill:
gridTrackRepetition = TSCGridTrackRepetition.AutoFill;
break;
case TSCGridTrackRepetition.AutoFit:
gridTrackRepetition = TSCGridTrackRepetition.AutoFit;
break;
case GridTrackRepetition.AutoFit:
gridTrackRepetition = GridTrackRepetition.AutoFit;
case TSCGridTrackRepetition.Count:
gridTrackRepetition = GridTrackRepetition.Count(item.repeating_count);
break;
}
if (gridTrackRepetition === null) {
Expand Down Expand Up @@ -3535,11 +3559,14 @@ export function _setGridTemplateColumns(value: Array<GridTemplates>, instance: T
const tracks = Array.create('org.nativescript.mason.masonkit.MinMax', repeating.length);
let gridTrackRepetition = null;
switch (item.repeating_type) {
case GridTrackRepetition.AutoFill:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFill;
case TSCGridTrackRepetition.AutoFill:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFill.INSTANCE;
break;
case GridTrackRepetition.AutoFit:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFit;
case TSCGridTrackRepetition.AutoFit:
gridTrackRepetition = org.nativescript.mason.masonkit.GridTrackRepetition.AutoFit.INSTANCE;
break;
case TSCGridTrackRepetition.Count:
gridTrackRepetition = new org.nativescript.mason.masonkit.GridTrackRepetition.Count(item.repeating_count);
break;
}
if (gridTrackRepetition === null) {
Expand All @@ -3554,6 +3581,7 @@ export function _setGridTemplateColumns(value: Array<GridTemplates>, instance: T
}

const repeat = new org.nativescript.mason.masonkit.TrackSizingFunction.AutoRepeat(gridTrackRepetition, tracks);

array[i] = repeat;
} else {
const single = item.value as MinMaxType;
Expand Down Expand Up @@ -3585,11 +3613,14 @@ export function _setGridTemplateColumns(value: Array<GridTemplates>, instance: T

let gridTrackRepetition = null;
switch (item.repeating_type) {
case GridTrackRepetition.AutoFill:
gridTrackRepetition = GridTrackRepetition.AutoFill;
case TSCGridTrackRepetition.AutoFill:
gridTrackRepetition = TSCGridTrackRepetition.AutoFill;
break;
case TSCGridTrackRepetition.AutoFit:
gridTrackRepetition = TSCGridTrackRepetition.AutoFit;
break;
case GridTrackRepetition.AutoFit:
gridTrackRepetition = GridTrackRepetition.AutoFit;
case TSCGridTrackRepetition.Count:
gridTrackRepetition = GridTrackRepetition.Count(item.repeating_count);
break;
}
if (gridTrackRepetition === null) {
Expand Down
Loading

0 comments on commit d0e8a21

Please sign in to comment.