Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Added a clickable event to Line, Bar, Pie #155

Open
wants to merge 6 commits into
base: master
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coverage.html

# Dependency directory
node_modules
example/node_modules/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary as the line above it matches files in example/node_modules. Can we remove it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok! I will to remove it


# Example build directory
example/dist
Expand Down
3 changes: 2 additions & 1 deletion example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
unsafe.enable_getters_and_setters=true

[version]
^0.42.0

^0.42.0
8 changes: 5 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ android {
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def versionCodes = ["armeabi-v7a": 1, "x86": 2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace additions necessary?

def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
Expand All @@ -128,8 +128,10 @@ android {
dependencies {
compile project(':react-native-svg')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
// From node_modules
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.facebook.react:react-native:+'
compile 'com.android.support:design:23.4.0'
}

// Run this once to be able to run the application with BUCK
Expand Down
23 changes: 12 additions & 11 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".MainApplication"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this builds cleanly. You get this kind of an error message:

* What went wrong:
Exception while parsing the supplied manifest file .../example/android/app/src/main/AndroidManifest.xml
> The element type "application" must be terminated by the matching end-tag "</application>".```

android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
Expand All @@ -29,4 +30,4 @@
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example;

/**
* Created by young on 2017/5/10.
*/

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ExampleReactPackage implements ReactPackage {

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new RNBridge(reactContext));

return modules;
}

}
52 changes: 52 additions & 0 deletions example/android/app/src/main/java/com/example/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.io.IOError;

public class HomeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

Button bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("匿名内部类", "点击事件");


try {
Intent intent = new Intent();
intent.setClass(HomeActivity.this, MainActivity.class);
startActivity(intent);
} catch (IOError error) {
error.printStackTrace();
}

}
});
}

}
24 changes: 18 additions & 6 deletions example/android/app/src/main/java/com/example/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
// private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments

// @Override
// public boolean getUseDeveloperSupport() {
// return BuildConfig.DEBUG;
// }
//
// @Override
// protected List<ReactPackage> getPackages() {
// return Arrays.<ReactPackage>asList(
// new MainReactPackage(),
// new RNSvgPackage(),
// new ExampleReactPackage()
// );
// }
// };

private final ReactNativeHost mReactNativeHost = new RNHost(this);

@Override
protected List<ReactPackage> getPackages() {
Expand All @@ -29,7 +41,7 @@ protected List<ReactPackage> getPackages() {
}
};

@Override
@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace addition.

public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
Expand Down
113 changes: 113 additions & 0 deletions example/android/app/src/main/java/com/example/RNActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.example;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;

import com.facebook.react.*;
import com.facebook.react.BuildConfig;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage;

/**
* Created by young on 2017/5/10.
*/

public class RNActivity extends Activity implements DefaultHardwareBackBtnHandler {

private ReactRootView rnRootView;
private ReactInstanceManager rnInstanceManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// if (!Settings.canDrawOverlays(this)) {
// Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
// Uri.parse("package:" + getPackageName()));
// startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
// }
// }

rnRootView = new ReactRootView(this);
Log.i("加载RN模块", "测试");
ReactInstanceManagerBuilder builder = ReactInstanceManager.builder().setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(true)
.setInitialLifecycleState(LifecycleState.RESUMED);

RNHost host = (RNHost) ((ReactApplication) getApplication()).getReactNativeHost();

for (ReactPackage reactPackage : host.packages()) {
builder.addPackage(reactPackage);
}

rnInstanceManager = builder.build();
rnRootView.startReactApplication(rnInstanceManager, "example", null);

setContentView(rnRootView);
}

@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
}


@Override
protected void onPause() {
super.onPause();

if (rnInstanceManager != null) {
rnInstanceManager.onHostPause(this);
}
}

@Override
protected void onResume() {
super.onResume();

if (rnInstanceManager != null) {
rnInstanceManager.onHostResume(this, this);
}
}

@Override
protected void onDestroy() {
super.onDestroy();

if (rnInstanceManager != null) {
rnInstanceManager.onHostDestroy(this);
}
}

@Override
public void onBackPressed() {

if (rnInstanceManager != null) {
rnInstanceManager.onBackPressed();
} else {
super.onBackPressed();
}
}


@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_MENU && rnInstanceManager != null) {
rnInstanceManager.showDevOptionsDialog();
return true;
}
return super.onKeyUp(keyCode, event);
}
}
40 changes: 40 additions & 0 deletions example/android/app/src/main/java/com/example/RNBridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example;

/**
* Created by young on 2017/5/10.
*/


import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

public class RNBridge extends ReactContextBaseJavaModule {

public RNBridge(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "RNBridge";
}

@Nullable
@Override
public Map<String, Object> getConstants() {

final Map<String, Object> constants = new HashMap<>();
constants.put("abc", "ABC");
constants.put("bcd", "BCD");

return constants;
}
}
Loading