Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !19
This commit is contained in:
commit
734dbd8221
@ -15,16 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package pub.doric.plugin;
|
package pub.doric.plugin;
|
||||||
|
|
||||||
|
import android.view.Gravity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.extension.bridge.DoricPlugin;
|
import pub.doric.extension.bridge.DoricPlugin;
|
||||||
import pub.doric.extension.bridge.DoricMethod;
|
import pub.doric.extension.bridge.DoricMethod;
|
||||||
import pub.doric.extension.bridge.DoricPromise;
|
import pub.doric.extension.bridge.DoricPromise;
|
||||||
|
import pub.doric.utils.DoricUtils;
|
||||||
import pub.doric.utils.ThreadMode;
|
import pub.doric.utils.ThreadMode;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
|
import com.github.pengfeizhou.jscore.JSObject;
|
||||||
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: Doric
|
* @Description: Doric
|
||||||
@ -41,7 +45,25 @@ public class ModalPlugin extends DoricJavaPlugin {
|
|||||||
@DoricMethod(name = "toast", thread = ThreadMode.UI)
|
@DoricMethod(name = "toast", thread = ThreadMode.UI)
|
||||||
public void toast(JSDecoder decoder, DoricPromise promise) {
|
public void toast(JSDecoder decoder, DoricPromise promise) {
|
||||||
try {
|
try {
|
||||||
Toast.makeText(getDoricContext().getContext(), decoder.string(), Toast.LENGTH_SHORT).show();
|
JSObject jsObject = decoder.decode().asObject();
|
||||||
|
String msg = jsObject.getProperty("msg").asString().value();
|
||||||
|
JSValue gravityVal = jsObject.getProperty("gravity");
|
||||||
|
int gravity = Gravity.BOTTOM;
|
||||||
|
if (gravityVal.isNumber()) {
|
||||||
|
gravity = gravityVal.asNumber().toInt();
|
||||||
|
}
|
||||||
|
Toast toast = Toast.makeText(getDoricContext().getContext(),
|
||||||
|
jsObject.getProperty("msg").asString().value(),
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
if ((gravity & Gravity.TOP) == Gravity.TOP) {
|
||||||
|
toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, DoricUtils.dp2px(50));
|
||||||
|
} else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
|
||||||
|
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, DoricUtils.dp2px(50));
|
||||||
|
} else {
|
||||||
|
toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
toast.show();
|
||||||
} catch (ArchiveException e) {
|
} catch (ArchiveException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ export default [
|
|||||||
'src/LayoutDemo',
|
'src/LayoutDemo',
|
||||||
'src/EffectsDemo',
|
'src/EffectsDemo',
|
||||||
'src/ImageDemo',
|
'src/ImageDemo',
|
||||||
|
'src/ModalDemo',
|
||||||
]
|
]
|
@ -13,7 +13,7 @@ class CounterView extends ViewHolder<CountModel> {
|
|||||||
text({
|
text({
|
||||||
textSize: 40,
|
textSize: 40,
|
||||||
layoutConfig: {
|
layoutConfig: {
|
||||||
alignment: new Gravity().center(),
|
alignment: Gravity.Center,
|
||||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||||
},
|
},
|
||||||
@ -27,7 +27,7 @@ class CounterView extends ViewHolder<CountModel> {
|
|||||||
},
|
},
|
||||||
corners: 5,
|
corners: 5,
|
||||||
layoutConfig: {
|
layoutConfig: {
|
||||||
alignment: new Gravity().center(),
|
alignment: Gravity.Center,
|
||||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||||
},
|
},
|
||||||
@ -43,9 +43,9 @@ class CounterView extends ViewHolder<CountModel> {
|
|||||||
it.width = 200
|
it.width = 200
|
||||||
it.height = 200
|
it.height = 200
|
||||||
it.space = 20
|
it.space = 20
|
||||||
it.gravity = new Gravity().center()
|
it.gravity = Gravity.Center
|
||||||
it.layoutConfig = {
|
it.layoutConfig = {
|
||||||
alignment: new Gravity().center()
|
alignment: Gravity.Center
|
||||||
}
|
}
|
||||||
it.border = {
|
it.border = {
|
||||||
width: 1,
|
width: 1,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig } from "doric";
|
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig, Gravity } from "doric";
|
||||||
import { colors } from "./utils";
|
import { colors } from "./utils";
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ function boxStr(str: string, idx = 0) {
|
|||||||
return (new Text).also(it => {
|
return (new Text).also(it => {
|
||||||
it.width = it.height = 20
|
it.width = it.height = 20
|
||||||
it.text = str
|
it.text = str
|
||||||
it.textColor = Color.parse('#ffffff')
|
it.textColor = Color.WHITE
|
||||||
it.bgColor = colors[idx || 0]
|
it.bgColor = colors[idx || 0]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class EffectsDemo extends Panel {
|
|||||||
width: 100,
|
width: 100,
|
||||||
height: 100
|
height: 100
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -56,7 +56,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -69,7 +69,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10
|
bottom: 10
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -88,7 +88,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10
|
bottom: 10
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
]).apply({ space: 20 } as IHLayout),
|
]).apply({ space: 20 } as IHLayout),
|
||||||
@ -109,7 +109,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -132,7 +132,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10
|
bottom: 10
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -152,7 +152,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10
|
bottom: 10
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -178,7 +178,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
]).apply({ space: 20 } as IHLayout),
|
]).apply({ space: 20 } as IHLayout),
|
||||||
@ -202,7 +202,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10,
|
bottom: 10,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -224,7 +224,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10,
|
bottom: 10,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -246,7 +246,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10,
|
bottom: 10,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -268,7 +268,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 10,
|
bottom: 10,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
]).apply({ space: 20 } as IHLayout),
|
]).apply({ space: 20 } as IHLayout),
|
||||||
@ -285,7 +285,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -302,7 +302,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -319,7 +319,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -336,7 +336,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
vlayout([
|
vlayout([
|
||||||
@ -353,7 +353,7 @@ class EffectsDemo extends Panel {
|
|||||||
bottom: 5,
|
bottom: 5,
|
||||||
})
|
})
|
||||||
}),]).apply({
|
}),]).apply({
|
||||||
gravity: gravity().center(),
|
gravity: Gravity.Center,
|
||||||
space: 10,
|
space: 10,
|
||||||
} as IVLayout),
|
} as IVLayout),
|
||||||
]).apply({ space: 20 } as IHLayout),
|
]).apply({ space: 20 } as IHLayout),
|
||||||
|
62
demo/src/ModalDemo.ts
Normal file
62
demo/src/ModalDemo.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, IText, modal } from "doric";
|
||||||
|
import { colors, label } from "./utils";
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
class ModalDemo extends Panel {
|
||||||
|
build(rootView: Group): void {
|
||||||
|
scroller(vlayout([
|
||||||
|
text({
|
||||||
|
text: "Modal",
|
||||||
|
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
bgColor: colors[1],
|
||||||
|
textAlignment: Gravity.Center,
|
||||||
|
height: 50,
|
||||||
|
}),
|
||||||
|
label('toast on bottom'),
|
||||||
|
label('Click me').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
onClick: () => {
|
||||||
|
modal(context).toast('This is a toast.')
|
||||||
|
}
|
||||||
|
} as IText),
|
||||||
|
label('toast on top'),
|
||||||
|
label('Click me').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
onClick: () => {
|
||||||
|
modal(context).toast('This is a toast.', Gravity.Top)
|
||||||
|
}
|
||||||
|
} as IText),
|
||||||
|
|
||||||
|
label('toast on center'),
|
||||||
|
label('Click me').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
onClick: () => {
|
||||||
|
modal(context).toast('This is a toast.', Gravity.Center)
|
||||||
|
}
|
||||||
|
} as IText),
|
||||||
|
]).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||||
|
gravity: Gravity.Center,
|
||||||
|
space: 10,
|
||||||
|
} as IVLayout)).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost(),
|
||||||
|
}).in(rootView)
|
||||||
|
}
|
||||||
|
}
|
@ -20,16 +20,19 @@
|
|||||||
// Created by pengfei.zhou on 2019/7/29.
|
// Created by pengfei.zhou on 2019/7/29.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <Doric/Doric.h>
|
||||||
#import "DoricModalPlugin.h"
|
#import "DoricModalPlugin.h"
|
||||||
#import "DoricRegistry.h"
|
#import "DoricUtil.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation DoricModalPlugin
|
@implementation DoricModalPlugin
|
||||||
|
|
||||||
- (void)toast:(NSString *)message withPromise:(DoricPromise *)promise {
|
- (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSLog(@"toast:%@", message);
|
__block DoricGravity gravity = BOTTOM;
|
||||||
[promise resolve:@"Resolved"];
|
[dic[@"gravity"] also:^(NSNumber *it) {
|
||||||
|
gravity = (DoricGravity) [it integerValue];
|
||||||
|
}];
|
||||||
|
showToast(dic[@"msg"], gravity);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricLayouts.h"
|
||||||
|
|
||||||
void DoricLog(NSString *_Nonnull format, ...);
|
void DoricLog(NSString *_Nonnull format, ...);
|
||||||
|
|
||||||
@ -35,3 +36,5 @@ NSBundle *_Nonnull DoricBundle(void);
|
|||||||
#ifndef DC_UNLOCK
|
#ifndef DC_UNLOCK
|
||||||
#define DC_UNLOCK(lock) dispatch_semaphore_signal(lock);
|
#define DC_UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void showToast(NSString *_Nonnull text, DoricGravity gravity);
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
#import "DoricContext.h"
|
#import "DoricContext.h"
|
||||||
|
#import "UIView+Doric.h"
|
||||||
|
|
||||||
void DoricLog(NSString *_Nonnull format, ...) {
|
void DoricLog(NSString *_Nonnull format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -45,3 +46,32 @@ void DoricLog(NSString *_Nonnull format, ...) {
|
|||||||
NSURL *url = [bundle URLForResource:@"Doric" withExtension:@"bundle"];
|
NSURL *url = [bundle URLForResource:@"Doric" withExtension:@"bundle"];
|
||||||
return [NSBundle bundleWithURL:url];
|
return [NSBundle bundleWithURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void showToast(NSString *text, DoricGravity gravity) {
|
||||||
|
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
|
||||||
|
UILabel *label = [[UILabel alloc] init];
|
||||||
|
label.font = [UIFont systemFontOfSize:20.f];
|
||||||
|
label.text = text;
|
||||||
|
label.textAlignment = NSTextAlignmentCenter;
|
||||||
|
label.layer.masksToBounds = YES;
|
||||||
|
label.backgroundColor = [UIColor grayColor];
|
||||||
|
label.textColor = [UIColor whiteColor];
|
||||||
|
[label sizeToFit];
|
||||||
|
label.width += 30;
|
||||||
|
label.height += 10;
|
||||||
|
label.layer.cornerRadius = label.height / 2;
|
||||||
|
label.centerX = superView.width / 2;
|
||||||
|
if ((gravity & BOTTOM) == BOTTOM) {
|
||||||
|
label.bottom = superView.height - 20;
|
||||||
|
} else if ((gravity & TOP) == TOP) {
|
||||||
|
label.top = 108;
|
||||||
|
} else {
|
||||||
|
label.centerY = (superView.height - 88) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
[superView addSubview:label];
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
|
[label removeFromSuperview];
|
||||||
|
});
|
||||||
|
}
|
@ -28,3 +28,4 @@ export * from './src/util/gravity'
|
|||||||
export * from './src/util/candies'
|
export * from './src/util/candies'
|
||||||
export * from './src/vm/mvvm'
|
export * from './src/vm/mvvm'
|
||||||
export * from './src/runtime/global'
|
export * from './src/runtime/global'
|
||||||
|
export * from './src/util/modal'
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
export * from 'reflect-metadata'
|
export * from 'reflect-metadata'
|
||||||
|
|
||||||
|
export type BridgeContext = { [index: string]: { [index: string]: (args?: any) => Promise<any> } }
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const context: { [index: string]: { [index: string]: (args?: any) => Promise<any> } };
|
const context: BridgeContext
|
||||||
function Entry(constructor: { new(...args: any[]): {} }): any
|
function Entry(constructor: { new(...args: any[]): {} }): any
|
||||||
}
|
}
|
||||||
export { }
|
export { }
|
@ -37,45 +37,65 @@ export class Gravity implements Modeling {
|
|||||||
val = 0
|
val = 0
|
||||||
|
|
||||||
left() {
|
left() {
|
||||||
this.val |= LEFT
|
const val = this.val | LEFT
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
right() {
|
right() {
|
||||||
this.val |= RIGHT
|
const val = this.val | RIGHT
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
top() {
|
top() {
|
||||||
this.val |= TOP
|
const val = this.val | TOP
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom() {
|
bottom() {
|
||||||
this.val |= BOTTOM
|
const val = this.val | BOTTOM
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
center() {
|
center() {
|
||||||
this.val |= CENTER
|
const val = this.val | CENTER
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
centerX() {
|
centerX() {
|
||||||
this.val |= CENTER_X
|
const val = this.val | CENTER_X
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
centerY() {
|
centerY() {
|
||||||
this.val |= CENTER_Y
|
const val = this.val | CENTER_Y
|
||||||
return this
|
const ret = new Gravity
|
||||||
|
ret.val = val
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
toModel() {
|
toModel() {
|
||||||
return this.val
|
return this.val
|
||||||
}
|
}
|
||||||
|
private static origin = new Gravity
|
||||||
|
|
||||||
|
static Center = Gravity.origin.center()
|
||||||
|
static Left = Gravity.origin.left()
|
||||||
|
static Right = Gravity.origin.right()
|
||||||
|
static Top = Gravity.origin.top()
|
||||||
|
static Bottom = Gravity.origin.bottom()
|
||||||
}
|
}
|
||||||
export function gravity() {
|
export function gravity() {
|
||||||
return new Gravity
|
return new Gravity
|
||||||
|
15
js-framework/src/util/modal.ts
Normal file
15
js-framework/src/util/modal.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { BridgeContext } from "../runtime/global";
|
||||||
|
import { Gravity } from "./gravity";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function modal(context: BridgeContext) {
|
||||||
|
return {
|
||||||
|
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
|
||||||
|
context.modal.toast({
|
||||||
|
msg,
|
||||||
|
gravity: gravity.toModel(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user