Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Custom touch tracking property instead of accessibilityLabel #2712

Merged
merged 5 commits into from
Jan 4, 2023
Merged
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
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking changes

- Message event current stack trace moved from exception to threads ([#2694](https://github.com/getsentry/sentry-react-native/pull/2694))
- `touchEventBoundaryProps.labelName` property instead of default `accessibilityLabel` fallback ([#2712](https://github.com/getsentry/sentry-react-native/pull/2712))

### Fixes

Expand Down Expand Up @@ -1074,10 +1075,10 @@ This release is a breaking change an code changes are necessary.
New way to import and init the SDK:

```js
import * as Sentry from "@sentry/react-native";
import * as Sentry from '@sentry/react-native';

Sentry.init({
dsn: "DSN",
dsn: 'DSN',
});
```

Expand Down Expand Up @@ -1312,7 +1313,7 @@ We decided to deactivate stack trace merging by default on iOS since it seems to
To activate it set:

```js
Sentry.config("___DSN___", {
Sentry.config('___DSN___', {
deactivateStacktraceMerging: false,
});
```
Expand Down
6 changes: 5 additions & 1 deletion sample/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ const App = () => {
};

// Wrap your app to get more features out of the box such as auto performance monitoring.
export default Sentry.wrap(App);
export default Sentry.wrap(App, {
touchEventBoundaryProps: {
labelName: 'custom-sentry-label-name',
},
});
2 changes: 1 addition & 1 deletion sample/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const HomeScreen = (props: Props) => {
onPress={() => {
Sentry.captureException(new Error('Test Error'));
}}
accessibilityLabel="captureException">
custom-sentry-label-name="captureException via custom Sentry label">
<Text style={styles.buttonText}>Capture Exception</Text>
</TouchableOpacity>
<View style={styles.spacer} />
Expand Down
22 changes: 16 additions & 6 deletions src/js/touchevents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export type TouchEventBoundaryProps = {
* React Node wrapped by TouchEventBoundary.
*/
children?: React.ReactNode;
/**
* Label Name used to identify the touched element.
*/
labelName?: string;
};

const touchEventStyles = StyleSheet.create({
Expand Down Expand Up @@ -96,8 +100,8 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
message: activeLabel
? `Touch event within element: ${activeLabel}`
: 'Touch event within component tree',
type: this.props.breadcrumbType
}
type: this.props.breadcrumbType,
};
addBreadcrumb(crumb);

logger.log(`[TouchEvents] ${crumb.message}`);
Expand Down Expand Up @@ -159,20 +163,26 @@ class TouchEventBoundary extends React.Component<TouchEventBoundaryProps> {
? `${props[PROP_KEY]}`
: undefined;

// For some reason type narrowing doesn't work as expected with indexing when checking it all in one go in
// the "check-label" if sentence, so we have to assign it to a variable here first
let labelValue;
if (typeof this.props.labelName === 'string')
labelValue = props?.[this.props.labelName];

// Check the label first
if (label && !this._isNameIgnored(label)) {
if (!activeLabel) {
activeLabel = label;
}
componentTreeNames.push(label);
} else if (
typeof props?.accessibilityLabel === 'string' &&
!this._isNameIgnored(props.accessibilityLabel)
typeof labelValue === 'string' &&
!this._isNameIgnored(labelValue)
) {
if (!activeLabel) {
activeLabel = props.accessibilityLabel;
activeLabel = labelValue;
}
componentTreeNames.push(props.accessibilityLabel);
componentTreeNames.push(labelValue);
} else if (currentInst.elementType) {
const { elementType } = currentInst;

Expand Down
15 changes: 10 additions & 5 deletions test/touchevents.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ describe('TouchEventBoundary._onTouchStart', () => {
expect(addBreadcrumb).not.toBeCalled();
});

it('label is preferred over accessibilityLabel and displayName', () => {
it('sentry-label is preferred over labelName and displayName', () => {
const { defaultProps } = TouchEventBoundary;
const boundary = new TouchEventBoundary(defaultProps);
const boundary = new TouchEventBoundary({
...defaultProps,
labelName: 'custom-sentry-label-name',
});

const event = {
_targetInst: {
Expand All @@ -66,7 +69,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
return: {
memoizedProps: {
'sentry-label': 'LABEL!',
accessibilityLabel: 'access!',
'custom-sentry-label-name': 'access!',
},
},
},
Expand All @@ -92,6 +95,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
const { defaultProps } = TouchEventBoundary;
const boundary = new TouchEventBoundary({
...defaultProps,
labelName: 'custom-sentry-label-name',
ignoreNames: ['View', 'Ignore', /^Connect\(/, new RegExp('^Happy\\(')],
});

Expand All @@ -111,7 +115,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
return: {
memoizedProps: {
'sentry-label': 'Ignore',
accessibilityLabel: 'Ignore',
'custom-sentry-label-name': 'Ignore',
},
elementType: {
displayName: 'Styled(View2)',
Expand Down Expand Up @@ -151,6 +155,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
const boundary = new TouchEventBoundary({
...defaultProps,
maxComponentTreeSize: 2,
labelName: 'custom-sentry-label-name',
});

const event = {
Expand All @@ -164,7 +169,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
},
return: {
memoizedProps: {
accessibilityLabel: 'Connect(View)',
'custom-sentry-label-name': 'Connect(View)',
},
return: {
elementType: {
Expand Down