Be sure to unlog the listening event
Page A
componentWillMount() {
this.subscription = DeviceEventEmitter.addListener("toggleEditMode", () => {
alert('registry a event listenr'); }); } Page A: alert('registry a event listenr'Page A: Alert ('registry a event listenr') X 2 Cause: RN does not automatically deregister events registered by us. Manual deregister method is required: Manually deregister events in the life cycle of componentWillUnmount, and pay attention to the existence of this event when deregister, and then execute the remove methodcomponentWillUnmountThis.subscription && this.subscription. Remove (); }Copy the code
Prohibit font enlargement along with system font
In an RN project that adjusts the system font, the font on the page changes with the system font, and we need to adjust the component properties: TextInput.defaultProps = Object.assign({}, TextInput.defaultProps, { defaultProps:false });
Text.defaultProps = Object.assign({}, Text.defaultProps, { allowFontScaling: false });
Copy the code
Capturing global errors ensures App stability
// Require () {require() {require();'ErrorUtils').setGlobalHandler(err => { });
Copy the code
Shield yellow warning with three finger slide
console.disableYellowBox = true/ / close all yellow warning console. ReportErrorsAsExceptions =false// Mask three-finger operation (some models that support three-finger operation may crash)Copy the code
Avoid heavy lifting during interactivity and animation
In order to avoid heavy operations in the process of interaction and animation, let JS execute other logic after the execution of animationcomponentDidMount() {InteractionManager. RunAfterInteractions (() = > {/ / switch tabs to access the page for the first time this. HandleChangeTab ('Usual'); This.loadusualdata (); }); } usesetImmediate or requestAnimationFrame to avoid heavy workload:setImmediate(() => { this.loadUsualData(); . . }); RequestAnimationFrame (() => {this.loadusualData (); . . }); Due to the single-threaded nature of JS, we should avoid doing many tasks at the same time, such as animation rendering, interface requests, or changing page stylesCopy the code