1
1
import { Application , Observable , Utils , fromObject } from '@nativescript/core' ;
2
2
import { FlutterCommon } from './common' ;
3
-
4
3
function makeFragmentName ( viewId : number ) : string {
5
4
return 'android:flutter:' + viewId ;
6
5
}
@@ -10,45 +9,55 @@ let flutterEngine: io.flutter.embedding.engine.FlutterEngine;
10
9
let channel : io . flutter . plugin . common . MethodChannel ;
11
10
let listener ;
12
11
const instances = new Map ( ) ;
12
+ let MethodCallClazz : java . lang . Class < io . flutter . plugin . common . MethodCall > ;
13
+ let argumentsMethod ;
13
14
export function init ( ) {
14
15
if ( ! didInit ) {
16
+ // todo remove remove after fixing runtime;
17
+ MethodCallClazz = java . lang . Class . forName ( 'io.flutter.plugin.common.MethodCall' ) ;
18
+ argumentsMethod = MethodCallClazz . getDeclaredMethod ( 'arguments' , [ ] ) ;
19
+
15
20
flutterEngine = new io . flutter . embedding . engine . FlutterEngine ( Utils . android . getApplicationContext ( ) ) ;
16
21
flutterEngine . getDartExecutor ( ) . executeDartEntrypoint ( io . flutter . embedding . engine . dart . DartExecutor . DartEntrypoint . createDefault ( ) ) ;
17
22
io . flutter . embedding . engine . FlutterEngineCache . getInstance ( ) . put ( 'default_nativescript' , flutterEngine ) ;
18
23
io . flutter . embedding . engine . plugins . util . GeneratedPluginRegister . registerGeneratedPlugins ( flutterEngine ) ;
19
- channel = new io . flutter . plugin . common . MethodChannel ( flutterEngine . getDartExecutor ( ) . getBinaryMessenger ( ) , 'nativescript' ) ;
24
+ channel = new io . flutter . plugin . common . MethodChannel ( flutterEngine . getDartExecutor ( ) . getBinaryMessenger ( ) , 'org. nativescript.flutter/channel ' ) ;
20
25
listener = new io . flutter . plugin . common . MethodChannel . MethodCallHandler ( {
21
26
onMethodCall ( call : io . flutter . plugin . common . MethodCall , result : io . flutter . plugin . common . MethodChannel . Result ) {
22
- const method = call . method ;
23
- if ( method . startsWith ( '__notify:' ) ) {
24
- try {
27
+ try {
28
+ const method = call . method ;
29
+ if ( method . startsWith ( '__notify:' ) ) {
25
30
const eventName = method . replace ( '__notify:' , '' ) ;
31
+ const args = argumentsMethod . invoke ( call , null ) ; //call.arguments();
32
+ const data = Utils . dataDeserialize ( args ) ;
26
33
Flutter . events . notify ( {
27
34
eventName,
28
35
object : fromObject ( { } ) ,
29
- data : Utils . dataDeserialize ( call . arguments ( ) ) ,
36
+ data,
30
37
} ) ;
31
38
result . success ( null ) ;
32
- } catch ( error ) {
33
- result . error ( '1000' , error . message , '' ) ;
34
- }
35
- } else if ( method === 'log' ) {
36
- console . log ( Utils . dataDeserialize ( call . arguments ( ) ) ) ;
37
- } else {
38
- const data = Utils . dataDeserialize ( call . arguments ( ) ) ;
39
- const instance : string | null = data ?. instance ;
40
- if ( instance ?. startsWith ( '__nativeNS:' ) ) {
41
- const ret = eval ( instance . replace ( '__nativeNS:' , '' ) ) ;
42
- result . success ( Utils . dataSerialize ( ret , true ) ) ;
43
- return ;
44
- } else if ( instance ?. startsWith ( '__nativeInstance:' ) ) {
45
- const id = instance . replace ( '__nativeInstance:' , '' ) ;
46
- const nativeInstance = instances . get ( id ) ;
47
- if ( nativeInstance ) {
48
- } else {
39
+ } else if ( method === 'log' ) {
40
+ const args = argumentsMethod . invoke ( call , null ) ; //call.arguments( );
41
+ console . log ( Utils . dataDeserialize ( args ) ) ;
42
+ } else {
43
+ const args = argumentsMethod . invoke ( call , null ) ; //call .arguments();
44
+ const data = Utils . dataDeserialize ( args ) ;
45
+ const instance : string | null = data ?. instance ;
46
+ if ( instance ?. startsWith ( '__nativeNS:' ) ) {
47
+ const ret = eval ( instance . replace ( '__nativeNS:' , '' ) ) ;
48
+ result . success ( Utils . dataSerialize ( ret , true ) ) ;
49
+ return ;
50
+ } else if ( instance ?. startsWith ( '__nativeInstance:' ) ) {
51
+ const id = instance . replace ( '__nativeInstance:' , '' ) ;
52
+ const nativeInstance = instances . get ( id ) ;
53
+ if ( nativeInstance ) {
54
+ } else {
55
+ }
49
56
}
57
+ console . log ( 'method' , method , 'arguments' , args ) ;
50
58
}
51
- console . log ( 'method' , method , 'arguments' , call . arguments ( ) ) ;
59
+ } catch ( error ) {
60
+ result . error ( '1000' , error . message , '' ) ;
52
61
}
53
62
} ,
54
63
} ) ;
@@ -60,7 +69,7 @@ export function init() {
60
69
}
61
70
62
71
export class Flutter extends FlutterCommon {
63
- _fragment : io . flutter . embedding . android . FlutterFragment & androidx . fragment . app . Fragment ;
72
+ _fragment : io . flutter . embedding . android . FlutterFragment ;
64
73
_androidViewId : number = - 1 ;
65
74
_activityCallbacks : android . app . Application . ActivityLifecycleCallbacks ;
66
75
_channel : io . flutter . plugin . common . MethodChannel ;
@@ -119,8 +128,8 @@ export class Flutter extends FlutterCommon {
119
128
120
129
const tr = fm . beginTransaction ( ) ;
121
130
122
- tr . replace ( this . _androidViewId , this . _fragment , name ) ;
131
+ tr . replace ( this . _androidViewId , this . _fragment as any , name ) ;
123
132
124
- tr . commitAllowingStateLoss ( ) ;
133
+ tr . commit ( ) ;
125
134
}
126
135
}
0 commit comments