Skip to content

Commit

Permalink
release v2.0.0-alpha.29
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Jan 5, 2024
1 parent 2bbba7d commit 19cba6e
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 61 deletions.
15 changes: 12 additions & 3 deletions packages/core/hooks/android/extractors/class-declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function extractClassDeclarationForModule(file: string) {
file.match(
/class\s+(\w+[^(\s]*)[\s\w():]*(\s+implements\s+|:)[\s\w():,]*[^{]*TurboModule/
);

if (turboModuleMatch) return turboModuleMatch;

const viewManagerMatch =
Expand All @@ -66,10 +67,18 @@ export function extractClassDeclarationForModule(file: string) {
);

if (moduleMatch) return moduleMatch;

const ktModuleMatch = file.match(
/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)ReactContextBaseJavaModule/gm
const specModuleMatch = file.match(
/public class\s+(\w+[^(\s]*)[\s\w():]*(\s+extends\s+|:)[\s\w():,]*[^{]*(\w+Spec)\s/
);
if (specModuleMatch) {
return specModuleMatch;
}

let ktModuleMatch =
file.match(
/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)ReactContextBaseJavaModule/gm
) ||
file.match(/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)(\w+Spec)/g);

return ktModuleMatch;
}
5 changes: 3 additions & 2 deletions packages/core/hooks/android/extractors/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ export async function extractPackageModules(folder: string) {
const moduleDeclarationMatch = extractClassDeclarationForModule(
file.contents
);

if (moduleDeclarationMatch) {
const [moduleClassSignature] = moduleDeclarationMatch;

const superclassName = moduleClassSignature.match(
/(?:extends\s+|:)(\w+)/
/(?:extends\s+|\s+:\s+)(\w+)/
)?.[1];
// if (!superclassName) {
// continue;
Expand Down
19 changes: 14 additions & 5 deletions packages/core/hooks/ios/extractors/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { extractModuleAliasedName } from './module-aliased-name';
* macros (e.g. RCT_EXPORT_METHOD).
*/
export function extractInterfaces(sourceCode: string, sourceFiles: string[]) {

/**
* Every swift module interface file should have this piece of code.
*/
Expand All @@ -36,14 +37,20 @@ export function extractInterfaces(sourceCode: string, sourceFiles: string[]) {
* ]
* }
*/


const moduleNamesToMethodDescriptions = [
...sourceCode.matchAll(
isSwiftModuleInterface
? /\s*@interface\s+RCT_EXTERN_MODULE\(\s*([A-z0-9$]+),\s+(?:.|[\r\n])*?@end/gm
: /\s*@implementation\s+([A-z0-9$]+)\s+(?:.|[\r\n])*?@end/gm
),
...sourceCode.matchAll(
/\s*@interface\s+RCT_EXTERN_MODULE\s+\(\s*([A-z0-9$]+),\s+(?:.|[\r\n])*?@end/gm
),
].reduce<ModuleNamesToMethodDescriptions>((acc, matches) => {
const [match, objcClassName] = matches;

if (!objcClassName) {
return acc;
}
Expand Down Expand Up @@ -74,10 +81,12 @@ export function extractInterfaces(sourceCode: string, sourceFiles: string[]) {
''
);


if (!exportedModuleName) {
return acc;
}


/**
* Extract the signatures of any methods registered using RCT_EXTERN_METHOD.
* @example
Expand Down Expand Up @@ -227,11 +236,11 @@ export function extractInterfaces(sourceCode: string, sourceFiles: string[]) {
...quickExportedMethods,
];

if (!allMethods.length) {
console.warn(
`${logPrefix} Unable to extract any methods from RCTBridgeModule named "${exportedModuleName}".`
);
}
// if (!allMethods.length) {
// console.warn(
// `${logPrefix} Unable to extract any methods from RCTBridgeModule named "${exportedModuleName}".`
// );
// }

const exportsConstants = isSwiftModuleInterface
? swiftImplContents?.includes('func constantsToExport()') || false
Expand Down
13 changes: 10 additions & 3 deletions packages/core/hooks/ios/getters/autolink-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,20 @@ export async function getPackageAutolinkInfo({

const subspecPaths = [];
const subspecs = {};
if (packageConfig?.podSubspecs) {
for (const subspecName of packageConfig.podSubspecs) {

const podSubspecs = packageConfig?.podSubspecs || (podspecParsed['subspecs']?.length === 1 && !podspecHasSourceFiles ? podspecParsed['subspecs'].map(name => name.name) : []);
if (podSubspecs) {
for (const subspecName of podSubspecs) {
const subspec = podspecParsed['subspecs']?.find(
(subspec) => subspec.name === subspecName
);
if (subspec) {
subspecs[subspecName] = subspec;
subspecPaths.push(...subspec.source_files);
if (typeof subspec.source_files === 'string') {
subspecPaths.push(subspec.source_files);
} else {
subspecPaths.push(...subspec.source_files);
}
} else {
console.warn(
`${logPrefix} Subspec ${subspecName} was not found in "${podspecFileName}" for npm package "${packageName}".`
Expand All @@ -136,6 +142,7 @@ export async function getPackageAutolinkInfo({
iosSourceFiles,
cwd: path.dirname(podspecFilePath),
});

// In a complicated pod setup, e.g. with subspecs, there may be special cases
// to handle. In practice, this is redundant for core modules (we don't
// augment the header at present), but it's good to be prepared for a future
Expand Down
25 changes: 21 additions & 4 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@ export type {
} from './Libraries/Utilities/Platform';
export { Linking } from './Libraries/Linking/Linking';
import EventEmitter from './Libraries/vendor/emitter/EventEmitter';
import { View } from '@nativescript/core';
export { AppRegistry } from './Libraries/ReactNative/AppRegistry';
export { Alert } from './Libraries/Alert/Alert';
export { ViewManagersIOS, requireNativeViewIOS } from './src/ios/viewmanagers';
export {BatchedBridge} from "./Libraries/BatchedBridge/BatchedBridge";
export { BatchedBridge } from './Libraries/BatchedBridge/BatchedBridge';
export {
ViewManagersAndroid,
requireNativeViewAndroid,
} from './src/android/viewmanagers';

export { requireNativeComponent } from './common';
export type OpenNativeBaseView<Props extends {}, Commands extends {}> = View & {
nativeProps: { [name: string]: any };
_viewTag: number;
_viewManager: {
setNativeProp(view: any, prop: string, ...params: any[]): void;
};
commands: {
[K in keyof Commands]: (...args: any[]) => void;
};
prototype: OpenNativeBaseView<Props, Commands>;
new (): OpenNativeBaseView<Props, Commands>;
} & Props &
Commands;

export function requireNativeComponent(
componentName: string
): OpenNativeBaseView<{}, {}>;

export type NativeSyntheticEvent<T> = {
nativeEvent: T
}
nativeEvent: T;
};

declare global {
// eslint-disable-next-line no-var
Expand Down
16 changes: 8 additions & 8 deletions packages/core/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import RCTDeviceEventEmitter from './Libraries/EventEmitter/RCTDeviceEventEmitter';
import * as _TurboModuleRegistry from './Libraries/TurboModule/TurboModuleRegistry';
import { load } from './src/ios/nativemodules';
import {
load as loadViewManagers,
requireNativeViewIOS,
} from './src/ios/viewmanagers';
export { Alert } from './Libraries/Alert/Alert';
export { BatchedBridge } from "./Libraries/BatchedBridge/BatchedBridge";
export { default as NativeEventEmitter } from './Libraries/EventEmitter/NativeEventEmitter';
export { Linking } from './Libraries/Linking/Linking';
export { AppRegistry } from './Libraries/ReactNative/AppRegistry';
export type { TurboModule } from './Libraries/TurboModule/RCTExport';
export { Dimensions } from './Libraries/Utilities/Dimensions';
export { Platform } from './Libraries/Utilities/Platform';
export { NativeModules } from './src/ios/nativemodules';
export const DeviceEventEmitter = RCTDeviceEventEmitter;
export {BatchedBridge} from "./Libraries/BatchedBridge/BatchedBridge";
export { Dimensions } from './Libraries/Utilities/Dimensions';
export { Alert } from './Libraries/Alert/Alert';
export { ViewManagersIOS, requireNativeViewIOS } from './src/ios/viewmanagers';
import {
load as loadViewManagers,
requireNativeViewIOS,
} from './src/ios/viewmanagers';
export const DeviceEventEmitter = RCTDeviceEventEmitter;

export function requireNativeComponent(viewName: string) {
return requireNativeViewIOS(viewName as never);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-for-npm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-native/core",
"version": "2.0.0-alpha.22",
"version": "2.0.0-alpha.29",
"description": "Open Native helps cross platform communities work better together.",
"main": "index",
"types": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-native/core",
"version": "2.0.0-alpha.22",
"version": "2.0.0-alpha.29",
"description": "Open Native helps cross platform communities work better together.",
"main": "index",
"types": "index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.facebook.react.bridge;

import android.view.View;

import androidx.annotation.Nullable;

import com.facebook.common.internal.DoNotStrip;
Expand Down Expand Up @@ -37,6 +39,8 @@ public interface CatalystInstance {

JSIModule getJSIModule(JSIModuleType moduleType);

View resolveView(int tag);

Collection<NativeModule> getNativeModules();

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.facebook.react.uimanager;

import android.view.View;

import com.facebook.react.bridge.ReactApplicationContext;
public class NativeViewHierarchyManager {

public ReactApplicationContext reactApplicationContext;

public NativeViewHierarchyManager(ReactApplicationContext reactApplicationContext) {
this.reactApplicationContext = reactApplicationContext;
}

public final View resolveView(int tag){

return this.reactApplicationContext.getCatalystInstance().resolveView(tag);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.facebook.react.uimanager;

public interface UIBlock {
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import android.view.View;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -34,8 +35,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements UIMan

public static final String NAME = "UIManager";

private NativeViewHierarchyManager viewHierarchyManager;

public UIManagerModule(ReactApplicationContext context) {
super(context);
viewHierarchyManager = new NativeViewHierarchyManager(this.getReactApplicationContext());
}

@Override
Expand Down Expand Up @@ -88,9 +92,16 @@ public void removeUIManagerEventListener(UIManagerListener listener) {

}

public void addUIBlock(UIBlock block) {
block.execute(this.viewHierarchyManager);
}
public void prependUIBlock(UIBlock block) {
block.execute(this.viewHierarchyManager);
}

@Override
public View resolveView(int reactTag) {
return null;
return this.viewHierarchyManager.resolveView(reactTag);
}

public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap event) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/scripts/open-native.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ext {
targetSdkVersion = safeExtGetOpenNative("NS_DEFAULT_COMPILE_SDK_VERSION", 32) as int
androidXCoreVersion = safeExtGetOpenNative("ns_default_androidx_core_version", "1.8.0")
androidXCompatVersion = safeExtGetOpenNative("ns_default_androidx_appcompat_version", "1.5.1")
kotlinVersion = safeExtGetOpenNative("ns_default_kotlin_version", "1.7.10")
}

allprojects {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/android/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function RCTNativeAppEventEmitter() {

const viewRegistry = {};

export function getRegisteredViewForTag(tag: number) {
return viewRegistry[tag];
}

function RCTEventEmitter() {
return new com.facebook.react.uimanager.events.RCTEventEmitter({
receiveTouches(param0, param1, param2) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/android/catalyst-instance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getRegisteredViewForTag } from './bridge';
import { toJSValue } from './converter';
import { JSModules } from './js-modules';
import {
Expand Down Expand Up @@ -64,6 +65,9 @@ export default class CatalystInstance {
module[method](...((toJSValue(args) || []) as []));
}
},
resolveView(param0) {
return getRegisteredViewForTag(param0) || null;
}
});
}
}
Loading

0 comments on commit 19cba6e

Please sign in to comment.