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

feat: mmkv #328

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/mmkv-metal/src-native/android/MMKV"]
path = packages/mmkv-metal/src-native/android/MMKV
url = https://github.com/Tencent/MMKV.git
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ npm start
- [@nativescript/jetpack-compose](packages/jetpack-compose/README.md)
- [@nativescript/local-notifications](packages/local-notifications/README.md)
- [@nativescript/localize](packages/localize/README.md)
- [@nativescript/mmkv](packages/mmkv/README.md)
- [@nativescript/mmkv-metal](packages/mmkv-metal/README.md)
- [@nativescript/pdf](packages/pdf/README.md)
- [@nativescript/picker](packages/picker/README.md)
- [@nativescript/shared-notification-delegate](packages/shared-notification-delegate/README.md)
Expand Down
4 changes: 3 additions & 1 deletion apps/demo-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"@nativescript/swift-ui": "file:../../dist/packages/swift-ui",
"@nativescript/theme-switcher": "file:../../dist/packages/theme-switcher",
"@nativescript/twitter": "file:../../dist/packages/twitter",
"@nativescript/zip": "file:../../dist/packages/zip"
"@nativescript/zip": "file:../../dist/packages/zip",
"@nativescript/mmkv": "file:../../dist/packages/mmkv",
"@nativescript/mmkv-metal": "file:../../dist/packages/mmkv-metal"
},
"devDependencies": {
"@nativescript/android": "~8.4.0",
Expand Down
2 changes: 2 additions & 0 deletions apps/demo-angular/src/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const routes: Routes = [
{ path: 'jetpack-compose', loadChildren: () => import('./plugin-demos/jetpack-compose.module').then((m) => m.JetpackComposeModule) },
{ path: 'local-notifications', loadChildren: () => import('./plugin-demos/local-notifications.module').then((m) => m.LocalNotificationsModule) },
{ path: 'localize', loadChildren: () => import('./plugin-demos/localize.module').then((m) => m.LocalizeModule) },
{ path: 'mmkv', loadChildren: () => import('./plugin-demos/mmkv.module').then((m) => m.MmkvModule) },
{ path: 'mmkv-metal', loadChildren: () => import('./plugin-demos/mmkv-metal.module').then((m) => m.MmkvMetalModule) },
{ path: 'pdf', loadChildren: () => import('./plugin-demos/pdf.module').then((m) => m.PdfModule) },
{ path: 'picker', loadChildren: () => import('./plugin-demos/picker.module').then((m) => m.PickerModule) },
{ path: 'shared-notification-delegate', loadChildren: () => import('./plugin-demos/shared-notification-delegate.module').then((m) => m.SharedNotificationDelegateModule) },
Expand Down
6 changes: 6 additions & 0 deletions apps/demo-angular/src/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export class HomeComponent {
{
name: 'localize',
},
{
name: 'mmkv',
},
{
name: 'mmkv-metal',
},
{
name: 'pdf',
},
Expand Down
8 changes: 8 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv-metal.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ActionBar title="mmkv-metal" class="action-bar"> </ActionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Button text="Test mmkv-metal" (tap)="demoShared.testIt()" class="btn btn-primary"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
17 changes: 17 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv-metal.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, NgZone } from '@angular/core';
import { DemoSharedMmkvMetal } from '@demo/shared';
import {} from '@nativescript/mmkv-metal';

@Component({
selector: 'demo-mmkv-metal',
templateUrl: 'mmkv-metal.component.html',
})
export class MmkvMetalComponent {
demoShared: DemoSharedMmkvMetal;

constructor(private _ngZone: NgZone) {}

ngOnInit() {
this.demoShared = new DemoSharedMmkvMetal();
}
}
10 changes: 10 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv-metal.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
import { MmkvMetalComponent } from './mmkv-metal.component';

@NgModule({
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: MmkvMetalComponent }])],
declarations: [MmkvMetalComponent],
schemas: [NO_ERRORS_SCHEMA],
})
export class MmkvMetalModule {}
8 changes: 8 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ActionBar title="mmkv" class="action-bar"> </ActionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Button text="Test mmkv" (tap)="demoShared.testIt()" class="btn btn-primary"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
17 changes: 17 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, NgZone } from '@angular/core';
import { DemoSharedMmkv } from '@demo/shared';
import {} from '@nativescript/mmkv';

@Component({
selector: 'demo-mmkv',
templateUrl: 'mmkv.component.html',
})
export class MmkvComponent {
demoShared: DemoSharedMmkv;

constructor(private _ngZone: NgZone) {}

ngOnInit() {
this.demoShared = new DemoSharedMmkv();
}
}
10 changes: 10 additions & 0 deletions apps/demo-angular/src/plugin-demos/mmkv.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
import { MmkvComponent } from './mmkv.component';

@NgModule({
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: MmkvComponent }])],
declarations: [MmkvComponent],
schemas: [NO_ERRORS_SCHEMA],
})
export class MmkvModule {}
12 changes: 6 additions & 6 deletions apps/demo/nativescript.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { NativeScriptConfig } from '@nativescript/core';

export default {
id: 'org.nativescript.plugindemo',
id: 'io.github.triniwiz.plugindemo',
appResourcesPath: '../../tools/assets/App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
},
appPath: 'src',
cli: {
packageManager: 'npm'
packageManager: 'npm',
},
hooks: [
{
type: 'before-prepare',
script: '../../tools/scripts/before-prepare.js',
}
],
type: 'before-prepare',
script: '../../tools/scripts/before-prepare.js',
},
],
} as NativeScriptConfig;
2 changes: 2 additions & 0 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@nativescript/iqkeyboardmanager": "file:../../packages/iqkeyboardmanager",
"@nativescript/local-notifications": "file:../../packages/local-notifications",
"@nativescript/localize": "file:../../dist/packages/localize",
"@nativescript/mmkv": "file:../../packages/mmkv",
"@nativescript/mmkv-metal": "file:../../packages/mmkv-metal",
"@nativescript/pdf": "file:../../packages/pdf",
"@nativescript/picker": "file:../../packages/picker",
"@nativescript/shared-notification-delegate": "file:../../packages/shared-notification-delegate",
Expand Down
1 change: 1 addition & 0 deletions apps/demo/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Application } from '@nativescript/core';
import '@nativescript/mmkv-metal/local-storage';

// uncomment to test local notifications
// import "@nativescript/local-notifications";
Expand Down
2 changes: 2 additions & 0 deletions apps/demo/src/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<Button text="theme-switcher" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="twitter" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="zip" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="mmkv" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
<Button text="mmkv-metal" tap="{{ viewDemo }}" class="btn btn-primary view-demo"/>
</StackLayout>
</ScrollView>
</StackLayout>
Expand Down
67 changes: 67 additions & 0 deletions apps/demo/src/plugin-demos/mmkv-metal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Observable, EventData, Page } from '@nativescript/core';
import { DemoSharedMmkvMetal } from '@demo/shared';
import { NSCMMKV as NSCMMKVMetal, initialize as initializeMetal } from '@nativescript/mmkv-metal';

import { NSCMMKV, initialize } from '@nativescript/mmkv';

export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new DemoModel();
}

const key = 'k';
const iterations = 1000;

export class DemoModel extends DemoSharedMmkvMetal {
mmkvm: NSCMMKVMetal;
mmkv: NSCMMKVMetal;
constructor() {
super();
initializeMetal();
initialize();
console.time('NSCMMKV');
this.mmkv = new NSCMMKV();
console.timeEnd('NSCMMKV');

console.time('NSCMMKVMetal');
this.mmkvm = new NSCMMKVMetal();
console.timeEnd('NSCMMKVMetal');
this.mmkvm.clearAll();
this.mmkvm.clearMemoryCache();

this.mmkv.clearAll();
this.mmkv.clearMemoryCache();

this.mmkvm.set(key, 'hello');
this.bm(this.getFromMMKVM.bind(this));

this.mmkv.set(key, 'hello');
this.bm(this.getFromMMKV.bind(this));
this.mmkvm.close();
}

getFromMMKV(): string | undefined {
return this.mmkv.getString(key);
}

getFromMMKVM(): string | undefined {
return this.mmkvm.getString(key);
}

bm(func) {
try {
console.log(`Starting Benchmark...`);
const start = global.performance ? performance.now() : (__time() as any);
for (let i = 0; i < iterations; i++) {
func();
}
const end = global.performance ? performance.now() : (__time() as any);
const diff = end - start;
console.log(`Finished Benchmark ! Took ${diff.toFixed(4)}ms!`);
return diff;
} catch (e) {
console.error(`Failed Benchmark !`, e);
return 0;
}
}
}
14 changes: 14 additions & 0 deletions apps/demo/src/plugin-demos/mmkv-metal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<Page.actionBar>
<ActionBar title="mmkv-metal" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Button text="Test mmkv-metal" tap="{{ testIt }}" class="btn btn-primary"/>

</StackLayout>
</ScrollView>
</StackLayout>
</Page>
63 changes: 63 additions & 0 deletions apps/demo/src/plugin-demos/mmkv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Observable, EventData, Page } from '@nativescript/core';
import { DemoSharedMmkv } from '@demo/shared';
import { NSCMMKV } from '@nativescript/mmkv';

export function navigatingTo(args: EventData) {
const page = <Page>args.object;
page.bindingContext = new DemoModel();
}

const key = 'k';
const iterations = 1000;

export class DemoModel extends DemoSharedMmkv {
mmkv: NSCMMKV;
constructor() {
super();
this.mmkv = new NSCMMKV();
this.mmkv.clearAll();
this.mmkv.clearMemoryCache();
// this.mmkv.set('first', 'Osei');
// this.mmkv.set('age', 30);
// this.mmkv.set('metal', false);

// if (global.isAndroid) {
// const js = new java.lang.String('Fortune');
// const buf = java.nio.ByteBuffer.wrap(js.getBytes());
// this.mmkv.set('last', (ArrayBuffer as any).from(buf as any));
// } else {
// const data = NSString.stringWithString('Fortune').dataUsingEncoding(NSUTF8StringEncoding);
// this.mmkv.set('last', interop.bufferFromData(data));
// }

// console.log(this.mmkv.getString('first'));
// console.log(this.mmkv.getNumber('age'));
// console.log(this.mmkv.getBoolean('metal'));
// console.log(this.mmkv.getString('last'));
// console.time('test');
this.mmkv.set(key, 'hello');
this.bm(this.getFromMMKV.bind(this));
//this.mmkv.close();
}

getFromMMKV(): string | undefined {
return this.mmkv.getString(key);
}

bm(func) {
try {
console.log(`Starting Benchmark...`);
const start = performance.now() as any;
for (let i = 0; i < iterations; i++) {
func();
}
const end = performance.now() as any;
const diff = end - start;
console.log(`Finished Benchmark ! Took ${diff.toFixed(4)}ms!`);
return diff;
} catch (e) {
console.error(`Failed Benchmark !`, e);
return 0;
}
}
}
14 changes: 14 additions & 0 deletions apps/demo/src/plugin-demos/mmkv.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<Page.actionBar>
<ActionBar title="mmkv" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<StackLayout class="p-20">
<ScrollView class="h-full">
<StackLayout>
<Button text="Test mmkv" tap="{{ testIt }}" class="btn btn-primary"/>

</StackLayout>
</ScrollView>
</StackLayout>
</Page>
3 changes: 1 addition & 2 deletions packages/geolocation/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ export function getCurrentLocation(options?: Options): Promise<Location>;
*/
export function watchLocation(successCallback: successCallbackType, errorCallback: errorCallbackType, options?: Options): number;


/**
* Monitor for location permission change. Only on iOS!
* @param permissionCallback gets called on location permission state change
* @param errorCallback gets called on error
* @returns {number} the watch id
*/
export function watchPermissionStatus(permissionCallback: permissionCallbackType, errorCallback: errorCallbackType): number;
export function watchPermissionStatus(permissionCallback: permissionCallbackType, errorCallback: errorCallbackType): number;

/**
* Stop monitoring for location change. Parameter expected is the watchId returned from `watchLocation`.
Expand Down
7 changes: 2 additions & 5 deletions packages/google-maps/utils/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function intoNativeMarkerOptions(options: MarkerOptions) {
opts.icon(com.google.android.gms.maps.model.BitmapDescriptorFactory.defaultMarker(hueFromColor(color)));
}

if(typeof options?.opacity === 'number') {
if (typeof options?.opacity === 'number') {
opts.alpha(options.opacity);
}

Expand Down Expand Up @@ -275,10 +275,7 @@ export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) {
}

if (options?.bounds) {
opts.positionFromBounds(new com.google.android.gms.maps.model.LatLngBounds(
new com.google.android.gms.maps.model.LatLng(options.bounds.southwest.lat, options.bounds.southwest.lng),
new com.google.android.gms.maps.model.LatLng(options.bounds.northeast.lat, options.bounds.northeast.lng)
));
opts.positionFromBounds(new com.google.android.gms.maps.model.LatLngBounds(new com.google.android.gms.maps.model.LatLng(options.bounds.southwest.lat, options.bounds.southwest.lng), new com.google.android.gms.maps.model.LatLng(options.bounds.northeast.lat, options.bounds.northeast.lng)));
}

if (typeof options?.transparency) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading