OWSTextView.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
  3. //
  4. #import "OWSTextView.h"
  5. #import "Theme.h"
  6. NS_ASSUME_NONNULL_BEGIN
  7. const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
  8. = UIDataDetectorTypeLink | UIDataDetectorTypeAddress | UIDataDetectorTypeCalendarEvent;
  9. const UIDataDetectorTypes kOWSAllowedDataDetectorTypesExceptLinks
  10. = UIDataDetectorTypeAddress | UIDataDetectorTypeCalendarEvent;
  11. @implementation OWSTextView
  12. - (instancetype)initWithFrame:(CGRect)frame textContainer:(nullable NSTextContainer *)textContainer
  13. {
  14. if (self = [super initWithFrame:frame textContainer:textContainer]) {
  15. [self ows_applyTheme];
  16. }
  17. // Setting dataDetectorTypes is expensive. Do it just once.
  18. self.dataDetectorTypes = kOWSAllowedDataDetectorTypes;
  19. return self;
  20. }
  21. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
  22. {
  23. if (self = [super initWithCoder:aDecoder]) {
  24. [self ows_applyTheme];
  25. }
  26. self.dataDetectorTypes = kOWSAllowedDataDetectorTypes;
  27. return self;
  28. }
  29. - (void)ows_applyTheme
  30. {
  31. self.keyboardAppearance = Theme.keyboardAppearance;
  32. }
  33. // MARK: -
  34. - (void)ensureShouldLinkifyText:(BOOL)shouldLinkifyText
  35. {
  36. if (shouldLinkifyText) {
  37. // Setting dataDetectorTypes can be expensive, so we only update it when it's changed.
  38. if (self.dataDetectorTypes != kOWSAllowedDataDetectorTypes) {
  39. self.dataDetectorTypes = kOWSAllowedDataDetectorTypes;
  40. }
  41. } else {
  42. // Setting dataDetectorTypes can be expensive, so we only update it when it's changed.
  43. if (self.dataDetectorTypes != kOWSAllowedDataDetectorTypesExceptLinks) {
  44. self.dataDetectorTypes = kOWSAllowedDataDetectorTypesExceptLinks;
  45. }
  46. }
  47. }
  48. @end
  49. NS_ASSUME_NONNULL_END