Skip to content

Commit

Permalink
doric createLib DoricSVGView
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcoder1011 committed Jan 11, 2022
1 parent 4d0eb5c commit 18c9d0a
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
build/
bundle/
xcuserdata
.gradle
.idea/
Pods/
*.lock
*.xcworkspace/xcshareddata/xcdebugger/
package-lock.json
20 changes: 20 additions & 0 deletions Template.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pod::Spec.new do |s|
s.name = 'DoricSVGView'
s.version = '0.1.0'
s.summary = 'Doric extension library'

#s.description = <<-DESC
# DESC

s.homepage = 'http://xxx'
s.license = { :type => 'Apache-2.0', :file => 'LICENSE' }
s.author = { 'xxx' => 'xxx@xxx' }
s.source = { :git => 'git@xxx', :tag => s.version.to_s }

s.ios.deployment_target = '9.0'

s.source_files = 'iOS/Classes/**/*'
s.resource = "dist/**/*"
s.public_header_files = 'iOS/Classes/**/*.h'
s.dependency 'DoricCore'
end
Empty file added __doric_library__
Empty file.
46 changes: 46 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import groovy.json.JsonSlurper

def model = new JsonSlurper().parse(new File(project.getProjectDir().parent + File.separator + "package.json"))
def doricSDKVersion = model.dependencies.doric.replace("^", "").replace(">=","")

println("Doric Version:" + doricSDKVersion)

buildscript {
repositories {
mavenCentral()
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

rootProject.allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 29

sourceSets {
main.assets.srcDirs += "../dist"
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
}

dependencies {
api "pub.doric:core:$doricSDKVersion"
}
Empty file added android/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pub.doric.android.library.doricsvgview">

</manifest>
21 changes: 21 additions & 0 deletions android/src/main/java/pub/doric/library/DoricDemoPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pub.doric.library;

import com.github.pengfeizhou.jscore.JavaValue;

import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise;
import pub.doric.plugin.DoricJavaPlugin;

@DoricPlugin(name = "demoPlugin")
public class DoricDemoPlugin extends DoricJavaPlugin {
public DoricDemoPlugin(DoricContext doricContext) {
super(doricContext);
}

@DoricMethod
public void call(DoricPromise promise) {
promise.resolve(new JavaValue("This is from android"));
}
}
26 changes: 26 additions & 0 deletions android/src/main/java/pub/doric/library/TemplateLibrary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pub.doric.library;

import java.io.IOException;
import java.io.InputStream;

import pub.doric.Doric;
import pub.doric.DoricComponent;
import pub.doric.DoricLibrary;
import pub.doric.DoricRegistry;

@DoricComponent
public class DoricSVGViewLibrary extends DoricLibrary {
@Override
public void load(DoricRegistry registry) {
try {
InputStream is = Doric.application().getAssets().open("bundle_doricsvgview.js");
byte[] bytes = new byte[is.available()];
is.read(bytes);
String content = new String(bytes);
registry.registerJSBundle("doricsvgview", content);
} catch (IOException e) {
e.printStackTrace();
}
registry.registerNativePlugin(DoricDemoPlugin.class);
}
}
5 changes: 5 additions & 0 deletions iOS/Classes/DoricDemoPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>
#import <DoricCore/Doric.h>

@interface DoricDemoPlugin : DoricNativePlugin
@end
7 changes: 7 additions & 0 deletions iOS/Classes/DoricDemoPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "DoricDemoPlugin.h"

@implementation DoricDemoPlugin
- (void)call:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
[promise resolve:@"This is from iOS"];
}
@end
5 changes: 5 additions & 0 deletions iOS/Classes/TemplateLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>
#import <DoricCore/Doric.h>

@interface DoricSVGViewLibrary : DoricLibrary
@end
12 changes: 12 additions & 0 deletions iOS/Classes/TemplateLibrary.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import "DoricSVGViewLibrary.h"
#import "DoricDemoPlugin.h"

@implementation DoricSVGViewLibrary
- (void)load:(DoricRegistry *)registry {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [path stringByAppendingPathComponent:@"bundle_doricsvgview.js"];
NSString *jsContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil];
[registry registerJSBundle:jsContent withName:@"doricsvgview"];
[registry registerNativePlugin:DoricDemoPlugin.class withName:@"demoPlugin"];
}
@end
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib/DemoPlugin";
9 changes: 9 additions & 0 deletions lib/DemoPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BridgeContext } from "doric";

export function demoPlugin(context: BridgeContext) {
return {
call: () => {
return context.callNative("demoPlugin", "call") as Promise<string>;
},
};
}
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "doricsvgview",
"version": "0.1.0",
"main": "dist/bundle_doricsvgview.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "doric build",
"dev": "cd example && doric dev",
"clean": "cd example && doric clean",
"android": "cd example && doric run android",
"ios": "cd example && doric run iOS"
},
"license": "Apache-2.0",
"dependencies": {
"doric": ">=0.9.27",
"doric-cli": ">=0.9.27"
},
"devDependencies": {
"typescript": "^4.2.2",
"rollup": "^2.24.0",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-image": "^2.0.5",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.4.0"
}
}
21 changes: 21 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
export default [
{
input: `build/index.js`,
output: {
format: "cjs",
file: `dist/bundle_doricsvgview.js`,
sourcemap: true,
},
plugins: [resolve({ mainFields: ["jsnext"] }), commonjs(), json()],
external: ["reflect-metadata", "doric"],
onwarn: function (warning) {
if (warning.code === "THIS_IS_UNDEFINED") {
return;
}
console.warn(warning.message);
},
},
];
67 changes: 67 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"jsxFactory": "jsx.createElement",
"jsxFragmentFactory": "jsx.Fragment",
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "build/", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"resolveJsonModule": true
},
"include": [
"**/*.ts",
],
"exclude": [
"example/",
]
}

0 comments on commit 18c9d0a

Please sign in to comment.