Created
August 9, 2016 17:31
-
-
Save mattpodwysocki/ae2e9fa50614b22c37a26edc27ce179e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ReactNative.UIManager; | |
using System.Threading; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
namespace ReactNative.Views.TextInput | |
{ | |
class ReactPasswordBox : PasswordBox | |
{ | |
private int _eventCount; | |
public ReactPasswordBox() | |
{ | |
SizeChanged += OnSizeChanged; | |
} | |
public int CurrentEventCount | |
{ | |
get | |
{ | |
return _eventCount; | |
} | |
} | |
public bool ClearTextOnFocus | |
{ | |
get; | |
set; | |
} | |
public bool SelectTextOnFocus | |
{ | |
get; | |
set; | |
} | |
public int IncrementEventCount() | |
{ | |
return Interlocked.Increment(ref _eventCount); | |
} | |
protected override void OnGotFocus(RoutedEventArgs e) | |
{ | |
base.OnGotFocus(e); | |
if (ClearTextOnFocus) | |
{ | |
Text = ""; | |
} | |
if (SelectTextOnFocus) | |
{ | |
SelectionStart = 0; | |
SelectionLength = Text.Length; | |
} | |
} | |
private void OnSizeChanged(object sender, SizeChangedEventArgs e) | |
{ | |
this.GetReactContext() | |
.GetNativeModule<UIManagerModule>() | |
.EventDispatcher | |
.DispatchEvent( | |
new ReactTextChangedEvent( | |
this.GetTag(), | |
Text, | |
e.NewSize.Width, | |
e.NewSize.Height, | |
IncrementEventCount())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment