Commit 3919a2b1 by zeven

自动点击模块支持动态配置

parent f7fe935e
...@@ -2,6 +2,7 @@ module.exports = { ...@@ -2,6 +2,7 @@ module.exports = {
root: true, root: true,
extends: '@react-native-community', extends: '@react-native-community',
rules: { rules: {
"eslint-comments/no-unlimited-disable": 0,
"react-native/no-inline-styles": 0, "react-native/no-inline-styles": 0,
"no-unused-vars": 2, "no-unused-vars": 2,
"no-eval": 0, "no-eval": 0,
......
android @ 1fbbb7eb
Subproject commit 03b417e84da4ae78717555dce2d9e414f036d6e4 Subproject commit 1fbbb7eba77679e3f994946bbff48304a7206ea8
...@@ -60,7 +60,8 @@ class SearchGoods extends React.Component { ...@@ -60,7 +60,8 @@ class SearchGoods extends React.Component {
<Text <Text
style={styles.searchBtn} style={styles.searchBtn}
onPress={() => { onPress={() => {
cancelSearch(), this.setState({goodsArr: []}); cancelSearch();
this.setState({goodsArr: []});
}}> }}>
取消 取消
</Text> </Text>
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import {View, Text, Image, DeviceEventEmitter} from 'react-native'; import {View, Text, Image} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
// import RtcEngine from 'react-native-agora'; // import RtcEngine from 'react-native-agora';
...@@ -64,14 +64,15 @@ class FacePage extends Component { ...@@ -64,14 +64,15 @@ class FacePage extends Component {
} }
const setting = await AutoClick.isSettingsOn(); const setting = await AutoClick.isSettingsOn();
if (!setting) this.setState({setting: true}); // 展示按钮 if (!setting) this.setState({setting: true}); // 展示按钮
DeviceEventEmitter.addListener('wxpayfaceRegister', async () => { AutoClick.on('wxpayfaceRegister', async () => {
await AutoClick.clickBackKey();
if (this.faceBusy) return; if (this.faceBusy) return;
this.faceBusy = true; this.faceBusy = true;
await this.wechatFace(); // 点击开通重新调用 await this.wechatFace(); // 点击开通重新调用
this.faceBusy = false; this.faceBusy = false;
}); });
// 监听微信输入手机号事件 // 监听微信输入手机号事件
DeviceEventEmitter.addListener('wxpayfaceInput', ({text}) => { AutoClick.on('AccessibilityClick', ({text}) => {
if (!text) return; if (!text) return;
const match = /^\[(.+)]$/.exec(text); const match = /^\[(.+)]$/.exec(text);
if (!match) return; if (!match) return;
...@@ -314,7 +315,7 @@ class FacePage extends Component { ...@@ -314,7 +315,7 @@ class FacePage extends Component {
Speech.speak(tipText); Speech.speak(tipText);
if (ret.code !== 1) { if (ret.code !== 1) {
this.setState({tip: tipText, tipsModal: true, loadingModal: false}); this.setState({tip: tipText, tipsModal: true, loadingModal: false});
} } else if (this.sense) this.setState({loadingModal: false});
} }
} else { } else {
Speech.speak('正在重新识别,请靠中间站稳'); Speech.speak('正在重新识别,请靠中间站稳');
......
import React, {Component} from 'react'; import React, {Component} from 'react';
import { import {View, Text, Image, FlatList, Modal, Button} from 'react-native';
View,
Text,
Image,
FlatList,
Modal,
Button,
DeviceEventEmitter,
} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import Swiper from 'react-native-swiper'; import Swiper from 'react-native-swiper';
import QRCode from 'react-native-qrcode-svg'; import QRCode from 'react-native-qrcode-svg';
...@@ -65,8 +57,12 @@ class VerticalPage extends Component { ...@@ -65,8 +57,12 @@ class VerticalPage extends Component {
} }
} }
this.initSetting(); this.initSetting();
DeviceEventEmitter.addListener('wxpayfaceRegister', () => { AutoClick.on('wxpayfaceRegister', async () => {
this.wxFacepay(); // 点击开通重新调用 await AutoClick.clickBackKey();
if (this.faceBusy) return;
this.faceBusy = true;
await this.wxFacepay(); // 点击开通重新调用
this.faceBusy = false;
}); });
} }
......
import {NativeModules} from 'react-native'; import {NativeModules, DeviceEventEmitter} from 'react-native';
import mitt from '../utils/mitt';
// 事件常数值参考:https://www.apiref.com/android-zh/android/view/accessibility/AccessibilityEvent.html
let AutoClick = {}; let AutoClick = {};
const emitter = mitt();
if (!NativeModules.AutoClick) { if (!NativeModules.AutoClick) {
AutoClick = { AutoClick = {
...@@ -14,7 +18,62 @@ if (!NativeModules.AutoClick) { ...@@ -14,7 +18,62 @@ if (!NativeModules.AutoClick) {
return enable; return enable;
}, },
goSetting: NativeModules.AutoClick.goSetting, goSetting: NativeModules.AutoClick.goSetting,
clickBackKey: () => {
const {clickBackKey} = NativeModules.AutoClick;
return clickBackKey && clickBackKey();
},
setEvent: (...arg) => {
const {setEvent} = NativeModules.AutoClick;
setEvent && setEvent(...arg);
},
...emitter,
};
const wxPkg = 'com.tencent.wxpayface';
const alPkg = 'com.alipay.zoloz.smile';
const events = {
wxpayfaceConfirm: {
pkgName: wxPkg,
method: 'clickByText',
search: '确认支付',
parent: true,
},
wxpayfaceRegister: {
pkgName: wxPkg,
method: 'clickById',
search: `${wxPkg}:id/container_register_allow_button`,
parent: false,
},
smileConfirm: {
pkgName: alPkg,
method: 'clickByExact',
search: '确认',
parent: true,
},
smilePayConfirm: {
pkgName: alPkg,
method: 'clickByExact',
search: '确认支付',
parent: true,
},
}; };
Object.keys(events).map(key => {
AutoClick.setEvent(key, events[key]);
});
DeviceEventEmitter.addListener('AccessibilityEvent', e => {
if (e && e.key) emitter.emit(e.key);
});
DeviceEventEmitter.addListener('AccessibilityClick', e => {
emitter.emit('AccessibilityClick', e);
});
// 兼容旧版本代码
DeviceEventEmitter.addListener('wxpayfaceInput', e => {
emitter.emit('AccessibilityClick', e);
});
DeviceEventEmitter.addListener('wxpayfaceRegister', () => {
emitter.emit('wxpayfaceRegister');
});
} }
export default AutoClick; export default AutoClick;
/* eslint-disable */
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
* @name mitt
* @returns {Mitt}
*/
function mitt(all) {
all = all || Object.create(null);
return {
/**
* Register an event handler for the given type.
*
* @param {String} type Type of event to listen for, or `"*"` for all events
* @param {Function} handler Function to call in response to given event
* @memberOf mitt
*/
on: function on(type, handler) {
(all[type] || (all[type] = [])).push(handler);
},
/**
* Remove an event handler for the given type.
*
* @param {String} type Type of event to unregister `handler` from, or `"*"`
* @param {Function} handler Handler function to remove
* @memberOf mitt
*/
off: function off(type, handler) {
if (all[type]) {
all[type].splice(all[type].indexOf(handler) >>> 0, 1);
}
},
/**
* Invoke all handlers for the given type.
* If present, `"*"` handlers are invoked after type-matched handlers.
*
* @param {String} type The event type to invoke
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
* @memberOf mitt
*/
emit: function emit(type, evt) {
(all[type] || []).slice().map(function(handler) { handler(evt); });
(all['*'] || []).slice().map(function(handler) { handler(type, evt); });
},
};
}
module.exports = mitt;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment