Skip to content

Commit 99887cb

Browse files
committed
init
Signed-off-by: 2534290808 <[email protected]>
1 parent 7d9fbb1 commit 99887cb

File tree

19 files changed

+1990
-0
lines changed

19 files changed

+1990
-0
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/react-native-switchbutton.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 350 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Switch.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, {Component} from 'react';
2+
import {
3+
StyleSheet,
4+
View,
5+
Text,
6+
requireNativeComponent,
7+
findNodeHandle,
8+
UIManager,
9+
Platform,
10+
Switch as SwitchIOS
11+
} from 'react-native';
12+
import {ViewPropTypes,PropTypes} from './Util'
13+
const RCTSwitchButton = requireNativeComponent('RCTSwitchButton', RCTSwitchButton);
14+
15+
class Switch extends Component {
16+
17+
_onValueChange=(event)=>{
18+
this.props.onValueChange && this.props.onValueChange(event.nativeEvent.checked)
19+
}
20+
render() {
21+
if(Platform.OS==='ios'){
22+
return (
23+
<SwitchIOS
24+
{...this.props}
25+
/>
26+
)
27+
}else{
28+
var props = {...this.props};
29+
props.style=[styles.rctSwitchButton,this.props.style];
30+
props.onSwitchButtonChange=this._onValueChange;
31+
props.checkedColor=this.props.onTintColor;
32+
props.buttonColor=this.props.thumbTintColor;
33+
props.enabled=!this.props.disabled
34+
return (
35+
<RCTSwitchButton
36+
{...props}
37+
/>
38+
39+
)
40+
}
41+
}
42+
}
43+
var styles = StyleSheet.create({
44+
rctSwitchButton: {
45+
height: 31,
46+
width: 51,
47+
}
48+
});
49+
Switch.propTypes = {
50+
disabled:PropTypes.bool,
51+
value:PropTypes.bool,
52+
onValueChange:PropTypes.func,
53+
onTintColor:PropTypes.string,
54+
thumbTintColor:PropTypes.string,
55+
...ViewPropTypes,
56+
}
57+
export default Switch;

android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 26
5+
buildToolsVersion "27.0.3"
6+
7+
8+
defaultConfig {
9+
minSdkVersion 15
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
}
26+
27+
dependencies {
28+
compile fileTree(dir: 'libs', include: ['*.jar'])
29+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30+
exclude group: 'com.android.support', module: 'support-annotations'
31+
})
32+
compile "com.facebook.react:react-native:+"
33+
compile 'com.github.zcweng:switch-button:0.0.3@aar'
34+
testCompile 'junit:junit:4.12'
35+
36+
37+
}

android/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lmy.switchbutton;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.lmy.switchbutton.test", appContext.getPackageName());
25+
}
26+
}

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.lmy.switchbutton" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lmy.switchbutton;
2+
3+
/**
4+
* Created by lmy2534290808 on 2017/12/2.
5+
*/
6+
7+
public enum Events {
8+
SWITCH_BUTTON_CHANGE("onSwitchButtonChange");
9+
10+
private final String mName;
11+
12+
Events(final String name) {
13+
mName = name;
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return mName;
19+
}
20+
}

0 commit comments

Comments
 (0)